这是一个简单的,也许我有一个长脑屁或其他什么,但发生什么是形式用于设置记录只有当名称和他们的cpukey匹配然后它将继续,因为这是一个没有登录的公共页面,人们在不知道2组信息的情况下改变其他人的事情会很烦人。所以这里的问题是,函数本身实际上是完美无缺的,即使函数失败(由于一行或多行不匹配),生成的消息SUCCESS或FAILURE也会产生SUCCESS
以下是使用的代码。
if(isset($_POST['upduserNotify'])){
$ccurrentname = mysqli_real_escape_string($con, $_POST['ccnameVal']);
$cclientnotify = mysqli_real_escape_string($con, $_POST['cnotifyVal']);
$cclientcpuk = mysqli_real_escape_string($con, $_POST['ccpukeyVal']);
$changenot = "UPDATE clients SET notify = '$cclientnotify' WHERE cpukey = '$cclientcpuk' AND name = '".$_POST['ccnameVal']."'";
if (mysqli_query($con, $changenot)) {
echo'<div align ="center" style="color:#000000">Your Custom notification was updated successfully</div><br />';
} else {
echo'<div align ="center">You entered an incorrect CPUKEY/Name or used an invalid character</div><br />';
}
}
答案 0 :(得分:1)
运行的UPDATE
查询,但找不到要更新的行,仍然是成功的 - 它在没有遇到任何错误的情况下运行完成,因此mysqli_query
将返回TRUE
,per the docs。 (如果是SELECT
种查询,则会返回mysqli_result
个对象。)
如果您希望在找不到要更新的行时执行其他操作,则您需要查看the number of affected rows并采取相应措施。
答案 1 :(得分:-1)
if(isset($_POST['upduserNotify'])){
$ccurrentname = mysqli_real_escape_string($con, $_POST['ccnameVal']);
$cclientnotify = mysqli_real_escape_string($con, $_POST['cnotifyVal']);
$cclientcpuk = mysqli_real_escape_string($con, $_POST['ccpukeyVal']);
$changenot = "UPDATE `clients` SET `notify` = '$cclientnotify' WHERE `cpukey` = '$cclientcpuk' AND `name` = '$ccurrentname'";
if (mysqli_query($con, $changenot) && mysqli_affected_rows($con) == 1 )
{
echo'<div align ="center" style="color:#000000">Your Custom Xnotify was updated successfully</div><br />';
}
else if (mysqli_query($con, $changenot) && mysqli_affected_rows($con) == 0 )
{
echo'<div align ="center">You entered an incorrect CPUKEY/Name or used an invalid character</div><br />';
}
}