我正在尝试提交表单并在表 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/