此代码点击提交UPDATE用户邮箱和名称,但当我在浏览器中刷新页面时,此代码向MySQL发送一个空字符串,我的意思是在MySQL中刷新页面或浏览器列名称和电子邮件变空后,< / p>
$con=mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$name = mysqli_real_escape_string($con, $_POST['name']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$userid=$ss['user']['id'];
$sql="UPDATE table_users SET name = '$name', email = '$email' WHERE user_id='$userid' ";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "----1 record added";
mysqli_close
答案 0 :(得分:0)
更改为
if(isset($_POST['username'])){
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
}
你没有检查post中的值是否设置。