php - 为什么不使用以下代码将值插入数据库?

标签 php mysql

我正在尝试提交表单并在表 Status 中插入一个值。但它不起作用。有什么问题吗?

表名为“Status”,最后一列名为“Votes”,我想在其中插入值。我认为查询没有运行,因为它没有回显“完成”。

代码如下:

for($x = 0; $x < $arrlength; $x++) {
$ids=$idsorted[$x];
$sts=$stsorted[$x];
$profilenamearray=array();
$idnamequery="SELECT Name FROM signup WHERE Email='$ids'";
$idnamequeryrun=mysqli_query($mysqls, $idnamequery);
$rowidname=mysqli_fetch_assoc($idnamequeryrun);
$profilenamearray[]=$rowidname["Name"];
  ?>
          <h4 style="font-family:Arial, Helvetica, sans-serif; color: #008080; margin: 0px;"> 

          <?php echo $profilenamearray[0];

          ?> </h4>
          <p class="updates"><?php echo $sts; 

          $votequeryrun="";
          if (isset($_REQUEST['submitbutton']))
          {
                $votecheck="SELECT Votes FROM status WHERE statusupdate='$sts'";
                $votecheckrun=mysqli_query($mysqls, $votecheck);
                $rowvote=mysqli_fetch_assoc($votecheckrun);
                $nofvotes=$rowvote["Votes"];
                $nofvotesN=$nofvotes+1;
                echo $nofvotesN;
                    $votequery="INSERT INTO status(Votes) VALUES('$nofvotesN') WHERE statusupdate='$sts'";
                    $votequeryrun=mysqli_query($mysqls, $votequery);
                    if($votequeryrun)
                    {
                        echo "done";
                        header("Location: welcomehome.php");
                    }
            }

          ?></p>
  <form name="votes" method="post" action="">
         <input type="submit" name="submitbutton">Vote</input>
        </form>


          <hr>
          <?php
}
?>

最佳答案

如果您使用 WHERE 子句,您可能想使用 UPDATE。 INSERT 添加一个新行,因此没有必要使用 where 子句。

关于php - 为什么不使用以下代码将值插入数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33627264/

相关文章:

php - 使用 PHP 和 MySQL 的分组/分层报告

mysql - SQL数据库查询/结构

mysql - 中止 CHECK TABLE (mysql) 查询是否安全? (快速检查表 TBL_NAME)

mysql从包含重复项的列表中选择

php - 为什么我的图像在使用 readfile 加载时显示不正确

php - Javascript:等效于 PHP 的 hash_hmac() 与 RAW BINARY 输出?

php - 按用户 ID 排除用户

php - 带参数的 Doctrine2 DQL TRIM

mysql - 如何在 MySQL 中以正确的方式处理存储的 UTC 日期转换(夏令时)?

php - 使用docker nginx镜像时我将index.php放在哪里