删除WHERE并且没有按预期运行

时间:2014-03-17 16:58:06

标签: php sql where sql-delete

我正在尝试从数据库中删除行。 DELETE查询正在检查数组中日期的匹配,并且reason为空。我的代码是;

<?php
session_start();
include 'connection.php';
include 'DateTest.php';
$deleted = array();
$size = sizeof($dayOfTheWeek) - 1;

for ($count = 0; $count <= $size; $count++) {

$query = "DELETE FROM daysoff WHERE DATE(start) = '$dateMonthYearArr[$count]' AND reason = ''";               
mysql_query($query) or die("im dead1");  

$deleted[] = "Rota deleted for ". $dateMonthYearArr[$count] .".</br>";

}   $_SESSION['delete'] = $deleted;
header('Location: '. $_SERVER['HTTP_REFERER']) ;

?>

这个DELETE查询正在消亡,如果我删除其中一个WHERE个参数,任何一个,它都有效,但AND似乎是一个问题。这在哪里失败了?

1 个答案:

答案 0 :(得分:0)

尝试

$query = "DELETE FROM daysoff WHERE DATE(start) = '" . $dateMonthYearArr[$count] . "' AND reason = ''";   

看看它是怎么回事......