【发布时间】:2015-06-04 14:21:54
【问题描述】:
我试图在下面获取此代码以删除两个选定日期之间的所有日期。它显示提供的错误并且没有从数据库中删除任何内容,但我不知道为什么?如果有人愿意看一看,我将不胜感激。
if(isset($_POST['remove'])){
$servername = "localhost";
$username = "u779108225_admin";
$password = "password";
$dbname = "u779108225_main";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$date_from = $_POST['date_from'];
$date_from = strtotime($date_from); // Convert date to a UNIX timestamp
// Specify the end date. This date can be any English textual format
$date_to = $_POST['date_to'];
$date_to = strtotime($date_to); // Convert date to a UNIX timestamp
// Loop from the start date to end date and output all dates inbetween
for ($i=$date_from; $i<=$date_to; $i+=86400) {
$date = date("Y-m-d", $i);
echo $date;
$sql = "DELETE FROM calendar WHERE date = $date)";
if ($conn->query($sql) === TRUE) {
$complete = 'The dates have been removed from the database.';
} else {
$complete = 'An error has been detected, please try again later.';
}
}
echo $complete;
$conn->close();
}
我尝试将 SQL 部分中的变量更改为包含 '' 和 "" 但似乎没有任何效果?
【问题讨论】:
标签: php mysql database date mysqli