gpt4 book ai didi

如果记录不存在,php 不会返回消息 :"Record dont exist"

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

我制作了一个表单,如果 id“Telefoninumber”存在,该表单将更新表“Komentaar”。但即使我输入不存在的 ID,我仍然得到回显“记录已成功更新”。

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "client.id");

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Attempt update query execution
$sql = "UPDATE clientid SET Komentaar='OK' WHERE
Tele foni_number=5207245";

if(mysqli_query($link, $sql)){
echo "Records were updated successfully.";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>

最佳答案

如果执行查询,您正在打印记录已成功更新。当然,无论是否进行任何更改,查询都会执行。您必须使用 mysqli_affected_rows() 解决您的情况:是否有任何行受到影响

$sql = "UPDATE clientid SET Komentaar='OK' WHERE Telefoni_number=5207245";
$result = mysqli_query($link, $sql);
if(if (mysqli_affected_rows($link)){
echo "Records were updated successfully.";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

关于如果记录不存在,php 不会返回消息 :"Record dont exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56958503/

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