我有以下PHP代码来更新mysql中的日期字段,但日期不会更新。我做错了什么?
$id = $_GET['id']; //id is in the URL
$mysqli_insertUpdate = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); //open db conn
if (mysqli_connect_errno()) {
printf("Connect failed: %s", mysqli_connect_error());
exit();
}
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('EST');
}
$timestamp = $_POST['year'] . "-" . $_POST['mo'] . "-" . $_POST['day']; //derived from html fields for year, mo and day
$timestamp = strtotime($timestamp);//turn it into Unix time
$mysqldatetime = date("Y-m-d", $timestamp);
echo $mysqldatetime;//"2007-12-11"
$q_update = "UPDATE people a, markers b
SET `b.date`='2007-12-11' WHERE a.MarkerID = b.MarkerID and a.ID=".addslashes($id); //I'm just hard coding in the date here
$r_updatevictim = $mysqli_insertUpdate->query($q_update);
$mysqli_insertUpdate->close();
答案 0 :(得分:2)
你有
的反引号`b.date`
应该是
`b`.`date`
更好的方法是使用显式连接
UPDATE markers b
join people a on a.MarkerID = b.MarkerID
SET `b`.`date`='2007-12-11'
WHERE a.ID=".addslashes($id);