在MySQL PHP中添加add where子句

时间:2015-06-18 02:40:19

标签: php mysql where-clause

我有以下条款

$curSong = $wpdb->query("DELETE FROM ".$wpdb->prefix . "current_requests WHERE id='".$_POST['remove']."'");

和id喜欢将page_id = $ postid添加到WHERE子句

简单我知道,但它只是语法我有点不确定

由于

亨利

4 个答案:

答案 0 :(得分:1)

you can write sql command like
Delete FROM Table where id=123 AND page_id=789 AND route_id=567

as much as you want, you can add more conditions using 'AND' logical       
operator.

如果它可以帮助您将其标记为已回答。

答案 1 :(得分:0)

你是说这个?

$query = sprintf("DELETE FROM %scurrent_requests WHERE id='%s' AND page_id='%s'", $wpdb->prefix, $_POST['remove'], $postid);
$curSong = $wpdb->query($query);

您可以使用" AND"向where子句添加更多条件。操作

答案 2 :(得分:0)

$curSong = $wpdb->query("DELETE FROM ".$wpdb->prefix . "current_requests WHERE id='".$_POST['remove']."' AND page_id='$postid'");

答案 3 :(得分:0)

修改你的代码......

验证用户值以防止SQL注入

  

使用htmlspecialchars()htmlentities()

$remove= htmlspecialchars($_POST['remove']);
$curSong = $wpdb->query("DELETE FROM ".$wpdb->prefix . "`current_requests` WHERE `id`='$remove' and `page_id` = '$postid'");
  

注意:您可以使用and or运算符...

添加许多条件