我有一个用户的更新页面
所以fetch查询工作正常但是当我点击提交时它给我的个人资料已更新然后我刷新页面我看不到任何更新。
页面不显示任何错误 ,我对此很困惑......
这是我的代码:
if(isset($_POST['edit_profile'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$user_avatar = $_FILES ['user_avatar']['name'];
$user_avatar_temp = $_FILES['user_avatar']['tmp_name'];
move_uploaded_file($user_avatar_temp, "./user_avatar/$user_avatar");
if(empty($user_avatar)){
$query = "SELECT user_avatar FROM users WHERE username = '{$the_user_id}' ";
$select_image = mysqli_query($connection,$query);
if(!$select_image){
die('rip'.mysqli_error($connection));
}
while($row = mysqli_fetch_assoc($select_image)){
$user_avatar = $row['user_avatar'];
}
}
$param_password = password_hash($password,PASSWORD_DEFAULT);
$error = NULL;
if (empty($password)) {
$error = 'You forgot to choose a password!';
}
if (!$error) {
$query = "UPDATE users SET ";
$query .= "firstname = '{$firstname}', ";
$query .= "lastname = '{$lastname}', ";
$query .= "username = '{$username}', ";
$query .= "email = '{$email}', ";
$query .= "user_avatar = '{$user_avatar}', ";
$query .= "password = '{$param_password}', ";
$query .= "WHERE username = '{$the_user_id}' ";
}
$edit_user_query =mysqli_query($connection,$query);
if(!$edit_user_query){
die('rip'.mysqli_error($connection));
}
echo "<div class='alert alert-success fade in'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<strong>Success!</strong> Your profile has been edited
</div>";
}
您可以使用Pastebin上的表单查看完整代码:
答案 0 :(得分:0)
运行查询时,您没有检查错误是否为空;
if (!$error) {
$query = "UPDATE users SET ";
$query .= "firstname = '{$firstname}', ";
$query .= "lastname = '{$lastname}', ";
$query .= "username = '{$username}', ";
$query .= "email = '{$email}', ";
$query .= "user_avatar = '{$user_avatar}', ";
$query .= "password = '{$param_password}', ";
$query .= "WHERE username = '{$the_user_id}' ";
}
$edit_user_query =mysqli_query($connection,$query);
因此,如果出现错误,它将运行上一个选择查询。