dsxsou8465
2016-05-14 11:55
浏览 42
已采纳

具有多个条件的SQL更新

I know this is quite simple but I've been looking at this for awhile and can't seem to identify what the issue is. I want to update a row in a table using two criteria. When I use either criteria, the table updates fine but when I combine them, it doesn't work.

This is the query

$updatequery = "UPDATE query SET audio='$finalpath' WHERE content='$title' AND WHERE userid LIKE '%$regID%'";

An example of the reg id:

APA91bGHS59rrpM0sbX9PIYT3SzXs-W1yEtGa2xGMGJXi8O1vW2SrgN7koHDj2o6ZwKvkd3TxtzhktsiVtQNSYQRa4uNDF7Yy0VOf0BJfQOnJWMtN2WBQjmVDsuU-0GxmceNLd8SWqOM

An example of content : Where can I find a car

图片转代码服务由CSDN问答提供 功能建议

我知道这很简单,但我已经看了一段时间,似乎无法确定是什么 问题是。 我想使用两个条件更新表中的行。 当我使用任何一个条件时,表格更新正常,但当我将它们组合时,它不起作用。

这是查询

  $ updatequery =“UPDATE查询SET audio ='$ finalpath'WHERE content ='$ title'AND WHERE userid LIKE'%$ regID%'”; 
   
 
 

了reg ID的示例:

APA91bGHS59rrpM0sbX9PIYT3SzXs-W1yEtGa2xGMGJXi8O1vW2SrgN7koHDj2o6ZwKvkd3TxtzhktsiVtQNSYQRa4uNDF7Yy0VOf0BJfQOnJWMtN2WBQjmVDsuU-0GxmceNLd8SWqOM

的内容的例子: Where我能找到一个车

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dqq9695 2016-05-14 11:58
    已采纳
    WHERE content='$title' AND userid LIKE '%$regID%'
    

    Where is needed only once

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongru3726 2016-05-14 11:58

    You only need to use the where keyword once:

    $updatequery = 
    "UPDATE query SET audio='$finalpath' WHERE content='$title' AND userid LIKE '%$regID%'";
    # "WHERE" removed here ------------------------------------^
    

    Mandatory comment:
    Using string manipulation like this leaves your code vulnerable to SQL-injection attacks. You should really consider using prepared statements instead.

    评论
    解决 无用
    打赏 举报
  • dpfl37651 2016-05-14 11:58

    Your query is wrong.

    Try this:

     $updatequery = "UPDATE query SET audio='$finalpath' WHERE content='$title' AND userid LIKE '%$regID%'";
    

    EDIT: Where is needed only once.

    评论
    解决 无用
    打赏 举报
  • dongtuo6562 2016-05-14 11:58

    You can have only one WHERE clause, so this is a syntax error:

    WHERE content='$title' AND WHERE userid LIKE '%$regID%'
    

    Combine the logic in a single clause:

    WHERE content='$title' AND userid LIKE '%$regID%'
    

    The WHERE clause essentially works like conditionals in any other language. You can build up as complex a tree of boolean conditions as you like, as long as the whole thing resolves down to a boolean then it's fine.

    评论
    解决 无用
    打赏 举报