问题描述
- PHP MySQL Update修改数据库失败,无警告报错
-
<?phpif(isset($_POST['submit'])&& $_POST['submit']) { $UID=$_GET['ID']; $name=$_POST['uname']; $phone=$_POST['phone']; $email=$_POST['email']; $servername="localhost"; $username = "root"; $password = ""; $dbname = "records"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检测连接 if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);} $sql="UPDATE user SET u_name=$name,u_phone=$phone,u_email=$email WHERE id='$UID'"; if(mysqli_query($conn,$sql)){ echo "修改成功!";} else{ echo"修改失败!";} mysqli_close($conn); echo'<meta http-equiv="refresh" content="2;url=empManage.php">'; }
?>
解决方案
1.你所谓的失败是没有改掉你想要改的数据吧.先检查一下?UID的值对不对,未必是执行错误,可能是条件错误
2.在你的UPDATE里。$name,$phone,$email,前后都缺少单引号
解决方案二:
无警告报错,错误信息是什么?
解决方案三:
打印一下你那条sql,首先看是否有报错,接下来再注意那几个变量的地方
解决方案四:
$sql="UPDATE user SET u_name=$name,u_phone=$phone,u_email=$email WHERE id='$UID'";
应该为
$sql="UPDATE user SET u_name=" + $name + ",u_phone=" + $phone" + ",u_email=" + $email + " WHERE id=" + $UID;
解决方案五:
"UPDATE user SET u_name=$name,u_phone=$phone,u_email=$email WHERE id='$UID'",这句SQL语句仔细查查。
时间: 2024-11-20 14:33:04