$sql = "SELECT WSEmailAddress FROM wsmembers AS w, wsmemberinvites AS wi
WHERE w.MemberShipID = (SELECT IntroducingMemberID WHERE IntroducingMemberID = $introid)";
and I am getting this error
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE IntroducingMemberID = 1)' at line 2
I tried wrapping the $intro id var with apostrophes but it didn’t helped
$sql = "SELECT WSEmailAddress FROM wsmembers AS w, wsmemberinvites AS wi
WHERE w.MemberShipID = (SELECT IntroducingMemberID WHERE IntroducingMemberID = '$introid')";
At first: [color="#FF0000"]Never ever use unfiltered user input in your SQL queries! [/color](hope this is formatted prominent enough )
You always should use parameter binding if you want to use user input (which includes request parameters) in your db query. Otherwhise you open a big door for SQL injection attacks.
$command=Yii::app()->db->createCommand('SELECT .... WHERE IntroducingMemberID=:introid');
$command->bindValue(':introid',Yii::app()->request->getQuery('introid'));