我有以下代码更新表。我希望它只在更新表单的所有字段都填充值而不是空的情况下继续进行更新。检查更新是否成功
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$newphone = mysqli_real_escape_string($con, $_POST['newphone']);
$newemail = mysqli_real_escape_string($con, $_POST['newemail']);
$sql="UPDATE users SET PhoneNumber='$newphone', email='$newemail' WHERE name='$_SESSION[user]'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "Status info have been updated";
print "</h2><br><a href='index.php'>Return to Main Menu</a><br>";
mysqli_close($con);
?>
没关系mysql的code.I将它改成mysqli事后。为了检查更新的记录
mysqli_affected_rows($con);
查找到[空](HTTP:// PHP .net/manual/en/function.empty.php)函数。 – wavemode 2014-09-27 15:36:45
if(!empty($ sql){ur condition} – 2014-09-27 15:37:04
请澄清一下你的问题。你是否说你需要给用户发出一个错误信息,如果newphone或newemail字段没有填写,并避免执行'UPDATE'查询? – 2014-09-27 15:38:55