I'm having a little trouble writing an if statement to update a couple of database fields based on matching a student ID between 2 tables. This is a form where I pass the initial Student and Class IDs to the SQL statement (this works just fine, but when I try to add the IF statement layer, I keep getting a T_CLASS parse error.

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;

Can anyone tell me what I'm missing? I've tried separating these out with parens but this didn't make a difference.

Thanks!

You cannot reference mysql table columns in a php if statement.

Php if structure looks like this:

if ($var1 == $SID) 
{
  $sql = "";
}
elseif ($var2 == $SID)
{
  $sql = "";
}
else 
{
  echo 'no match';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.