我有一个名为pack_details的表,有4列。我正在尝试将新数据插入现有表中。有人能告诉我我的代码有什么问题吗?为什么我有解析错误?
$sql_query = "UPDATE pack_details SET $delivery_date = $_POST["delivery_date"], $delivery_time = $_POST["delivery_time"]
WHERE $delivery_building = $_POST["delivery_building"]
AND $delivery_room = $_POST["delivery_room"]";
答案 0 :(得分:1)
尝试以下任何选项:
$sql_query = "UPDATE pack_details SET $delivery_date = '{$_POST['delivery_date']}', $delivery_time = '{$_POST['delivery_time']}' WHERE $delivery_building = '{$_POST['delivery_building']}' AND $delivery_room = '{$_POST['delivery_room']}'";
或
$sql_query = "UPDATE pack_details SET delivery_date = '".$_POST["delivery_date"]."', delivery_time = '".$_POST["delivery_time"]."' WHERE delivery_building = '".$_POST["delivery_building"]."' AND delivery_room = '".$_POST["delivery_room"]."'";
注意:如果字段名称不包含$,请在查询中从字段名称中删除$。例如。 " $ DELIVERY_DATE"应该是" delivery_date"
建议:您应该使用绑定参数将值传递给查询,而不是使用字符串连接进行构建。它有助于防止SQL注入以及代码看起来很好。