dougu5847 2012-09-21 20:33
浏览 61
已采纳

PHP If MySQL查询语句

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?

  • 写回答

1条回答 默认 最新

  • dpjtn48868 2012-09-21 20:36
    关注

    You have an error in your syntax in your last else, remove the parens, so instead of this:

    else()
    

    it should be this

    else
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办