Page 1 of 1

Parse error in MySQL IF statement

Posted: Tue Sep 06, 2011 9:37 pm
by httpgal
I keep getting this error (below) can anyone tell me what I'm doing wrong? The SQL statement worked as a standalone, but boms as an IF statement...

Parse error: syntax error, unexpected T_CLASS, expecting '(' in /home/www/vhosts/contractor-training-ca.org/httpdocs/form_processors/do_confirm.php on line 11

Code: Select all


IF class.s1i=$SID THEN $sql="update students, class SET students.currentStatus='confirmed',students.timeStamp='$dateLastUpdated', class.s1s='confirmed' where students.SID=$SID";

ELSEIF class.s2i=$SID THEN $sql="update students, class SET students.currentStatus='confirmed',students.timeStamp='$dateLastUpdated', class.s2s='confirmed' where students.SID=$SID";

ELSE echo "no match";

END IF;


Re: Parse error in MySQL IF statement

Posted: Tue Sep 06, 2011 11:30 pm
by califdon
What language are you writing this in? What the parse error is telling you is that you are not using PHP syntax, which is very different from your IF ... THEN ... ELSEIF ... ELSE ... syntax. Take a look: http://php.net/manual/en/control-structures.elseif.php

Re: Parse error in MySQL IF statement

Posted: Wed Sep 07, 2011 5:35 am
by theyapps
Proper form for PHP IF statements should be something more like this. Sorry if its sloppy I'm half asleep haha

Code: Select all

IF ($SID == 'condition 1'){

$sql="update students, class SET students.currentStatus='confirmed',students.timeStamp='$dateLastUpdated', class.s1s='confirmed' where students.SID=$SID";

ELSEIF ($SID == 'condition 2') {

$sql="update students, class SET students.currentStatus='confirmed',students.timeStamp='$dateLastUpdated', class.s2s='confirmed' where students.SID=$SID";

} ELSE { 

echo "no match";

}