Reputation: 444
For the life of me I cannot figure this one out, still new so I am probably overlooking.
Based on a POST value, I would like to perform 1 of 3 MySQL queries. I have verified that each query works on its own, when I add the if statement nothing updates. Also not receiving any MySQL errors.
If the POST value is "on" or "off" run the corresponding query to update all columns. If the POST value is anything else (would be a column number), toggle that column.
<!-- language: lang-php -->
mysql_select_db("lightup") or die(mysql_error());
if ($light=="on")
{
$query = mysql_query("UPDATE Homes SET L1Status='0',L2Status='0',L3Status='0',L4Status='0',L5Status='0',L6Status='0',L7Status='0',L8Status='0',L9Status='0',L10Status='0' WHERE HomeID=$id") or die(mysql_error());
}
elseif ($light=="off")
{
$query = mysql_query("UPDATE Homes SET L1Status='0',L2Status='0',L3Status='0',L4Status='0',L5Status='0',L6Status='0',L7Status='0',L8Status='0',L9Status='0',L10Status='0' WHERE HomeID=$id") or die(mysql_error());
}
else()
{
$query = mysql_query("UPDATE Homes SET $lightcolumn = !$lightcolumn WHERE HomeID=$id") or die(mysql_error());
}
mysql_close($link);
Any thoughts?
Upvotes: 0
Views: 1062
Reputation: 50643
You have an error in your syntax in your last else
, remove the parens, so instead of this:
else()
it should be this
else
Upvotes: 4