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 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题