【问题标题】:After mysql_query, no result outputmysql_query之后,没有结果输出
【发布时间】:2011-02-24 19:53:41
【问题描述】:

我有一个简单的mysql_query() update 命令来更新mysql。

当用户提交我的表单时,它会跳转到一个更新页面来更新数据。问题是更新后应该显示一些数据,但它显示为空白。

我的表格

<form id="form1" method="POST" action="scheduleUpdate.php" >

  <select name=std1>
    <option>AA</option>
    <option>BB</option>
    <option>CC</option>
  </select>

  <select name=std2>
    <option>DD</option>
    <option>EE</option>
    <option>FF</option>
  </select>

.......//more drop down menu but the name is std3..std4..etc...
.......
</form>

scheduleUpdate.php

//$i is the value posted from my main app to tell me how many std we have

for($k=0;$k<$i;$k++){

    $std=$_POST['std'.$k];
//if i remove the updateQuery, the html will output.I know the query is the problem but i //couldn't fix it..
    $updateQuery=mysql_query("UPDATE board SET
                student='$std'
                WHERE badStudent='$std' or goodStudent='$std'",$connection);
        //no output below this line at all
        if($updateQuery){
        DIE('mysql Error:'+mysql_error());
        }

    }

// I have bunch of HTML here....but no output at all!!!!

点击提交后MySQL会更新,但没有显示任何HTML。

【问题讨论】:

  • NVM。我现在修复它...我的 if($updateQuery) 应该是 if(!updateQuery)........不敢相信这个小感叹号可能意味着很多!......
  • @Jerry 您可以将此作为答案发布并接受它,或者删除问题(链接就在这些 cmets 上方,在标签列表下)。编辑:或者接受最近提交的一个说同样事情的答案
  • 然后要么将其作为答案并接受它,要么删除此问题
  • 哇..你们真快。由于 jeroen 是第一人称回复。你得到了我接受的答案!并向所有人 +1

标签: php mysql forms select


【解决方案1】:

你的错误处理是错误的; $updateQuery 在成功时评估为 true,因此您会在成功而不是错误时终止程序。

【讨论】:

    【解决方案2】:

    不应该是:

    if(!$updateQuery)
    

    ?

    【讨论】:

      【解决方案3】:

      你不应该只在查询失败时死去失败

      if(!$updateQuery){
          die('mysql Error:'+mysql_error());
      }
      

      【讨论】:

        【解决方案4】:

        正如其他人所说,它可能应该是if(!$updateQuery){ 而不是if($updateQuery){。我本来希望你会看到输出“mysql Error:”。

        作为附加说明,请阅读 SQL 注入和清理用户输入,因为您似乎正在编写易受攻击的代码。

        【讨论】:

        • 用户只需要选择值,不能输入。我还需要担心清理数据吗?
        • 一般来说,您应该始终清理将进入数据库查询的任何内容。请记住,如果我愿意,我可以向您自己生成的页面提交 POST 数据,而不是使用您的页面。也就是说,你不能依赖你设计的“安全”格式的 POST 数据。
        【解决方案5】:

        根据您的示例表单,您应该在for 循环中以1 开头k,而不是0

        【讨论】:

          【解决方案6】:

          如果您执行上面的代码,您将获得显示“mysql Error:”的 HTML 输出,您的计数器变量 k 也应该从表单一开始,因为第一个表单元素的名称为 std1。

          【讨论】:

            猜你喜欢
            • 2012-11-04
            • 2014-06-29
            • 2013-03-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-08-07
            • 2020-04-17
            • 1970-01-01
            相关资源
            最近更新 更多