Php 重复密钥更新时-不更新
我的代码有问题,无法更新现有的计算机数据。如果我删除了ON replicate部分,代码就可以正常工作并添加数据。我已将计算机作为我的xampp数据库中的唯一密钥。任何帮助都将不胜感激Php 重复密钥更新时-不更新,php,mysql,mysqli,duplicates,Php,Mysql,Mysqli,Duplicates,我的代码有问题,无法更新现有的计算机数据。如果我删除了ON replicate部分,代码就可以正常工作并添加数据。我已将计算机作为我的xampp数据库中的唯一密钥。任何帮助都将不胜感激 <?php $receive = htmlspecialchars($_POST['time']); list($length, $status, $computer) = split(":", $receive, 3); include('connection.php'); mysqli_
<?php
$receive = htmlspecialchars($_POST['time']);
list($length, $status, $computer) = split(":", $receive, 3);
include('connection.php');
mysqli_query($dbc, "INSERT INTO screen(computer,status,length)
VALUES('$computer','$status','$length')
ON DUPLICATE KEY UPDATE
status=$status, length=$length");
?>
创建SQL语句的更好模式,可以缓解一些常见的SQL注入漏洞。还请注意,如果插入成功,特殊的VALUES()
函数可用于引用为列插入的值
$sql = "INSERT INTO screen(computer,status,length)
VALUES('"
. mysqli_real_escape_string($dbc,$computer)
. "','"
. mysqli_real_escape_string($dbc,$status)
. "','"
. mysqli_real_escape_string($dbc,$length)
. "')
ON DUPLICATE KEY UPDATE
status=VALUES(status), length=VALUES(length)";
mysqli_query($dbc,$sql);
你忘了计算你的更新值->updatestatus='$status',length='$length'
Sean-你是我的英雄。谢谢你的修复