Parse error in MySQL IF statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
httpgal
Forum Newbie
Posts: 1
Joined: Tue Sep 06, 2011 9:34 pm

Parse error in MySQL IF statement

Post 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;

User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Parse error in MySQL IF statement

Post 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
theyapps
Forum Newbie
Posts: 8
Joined: Tue Sep 06, 2011 12:47 am

Re: Parse error in MySQL IF statement

Post 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";

}
Post Reply