Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重复密钥更新时-不更新_Php_Mysql_Mysqli_Duplicates - Fatal编程技术网

Php 重复密钥更新时-不更新

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_

我的代码有问题,无法更新现有的计算机数据。如果我删除了ON replicate部分,代码就可以正常工作并添加数据。我已将计算机作为我的xampp数据库中的唯一密钥。任何帮助都将不胜感激

<?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-你是我的英雄。谢谢你的修复