gpt4 book ai didi

php - 使用 php 更新 MySQL 中的日期行和时间行

转载 作者:行者123 更新时间:2023-11-29 19:13:13 25 4
gpt4 key购买 nike

当我尝试更新表中的日期和时间行时,出现以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'date = '7890-06-06' time = '12:34:00' ' at line 3

不完全确定为什么我会得到这个,因为我在 sql 代码中使用 '' 并且表中的格式都是正确的。

PHP 代码:

<?php

include 'database_conn.php';

if(!$conn)
{
echo "Error connecting to database";
}

if (mysqli_connect_errno())
{
echo "<p>Connection failed:".mysqli_connect_error()."</p>\n";
}

$eventid = isset($_GET['eId']) ? $_GET['eId'] : NULL;
$title = isset($_REQUEST['titleField']) ? $_REQUEST['titleField'] : '';
$time = isset($_REQUEST['timeField']) ? $_REQUEST['timeField'] : '';
$date = isset($_REQUEST['dateField']) ? $_REQUEST['dateField'] : '';
$location = isset($_REQUEST['locationField']) ? $_REQUEST['locationField'] : '';
$description = isset($_REQUEST['descriptionField']) ? $_REQUEST['descriptionField'] : '';

//echo "Event: $eventid";
//echo "User: $uid";
//echo "Comment: $comment";
echo "$date";
echo "$time";

$sql = "UPDATE Events
SET name = '$title'
date = '$date'
time = '$time'
location = '$location'
description = '$description'

WHERE eventid = '$eventid'
";

$results = mysqli_query($conn, $sql)
or die(mysqli_error($conn));

if($results)
{
echo "Event successfully edited";
}

mysqli_close($conn);

?>

不确定表示表格的最佳方式,但它是:

#   Name    Type
1 eventid int(11)
2 name varchar(255)
3 date date
4 time time
5 location varchar(255)
6 description varchar(1000)

最佳答案

您应该在集合语句之间添加逗号分隔',':

   $sql = "UPDATE Events
SET name = '$title',
date = '$date',
time = '$time',
location = '$location',
description = '$description'

WHERE eventid = '$eventid'
";

关于php - 使用 php 更新 MySQL 中的日期行和时间行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42913214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com