duanshan7261 2014-04-02 19:52
浏览 20

mysql update子句被忽略了

I have a table with a date, ID1, ID2 score1 and score2. I am trying to update one row through php when the user has entered the specific date and id's in an html form. I have validated all the user entries. When I run my query it updates all rows in the table instead of just one. Here is a snippet of my code:

include('connect.php');

$q = mysqli_query($dbc, "SELECT * from Game");
while ($row =mysqli_fetch_array($q, MYSQLI_ASSOC))
{

    mysqli_query($dbc, "UPDATE Game SET score1 ='".$points1."', score2='".$points2."'
    WHERE '".$date."' = '".$row['Date']."' AND '".$id."' = '".$row['ID1']."' ");
}

mysqli_close($dbc);
  • 写回答

2条回答 默认 最新

  • dtx6087 2014-04-02 19:56
    关注

    Shouldn't your where clause be:

    WHERE Date = '".$row['Date']."' AND ID1 = '".$row['ID1']."' ");
    

    instead of

    WHERE '".$date."' = '".$row['Date']."' AND '".$id."' = '".$row['ID1']."' ");
    

    In the latter you - probably by accident - use some variables as field names as well, which might cause some unwanted issues. For example in your case it's likely to cause an identity condition in your where clause, which will result that all of your rows will get updated.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法