用户信息不会更新到数据库。这是一个更新用户信息的脚本。用户信息不会更新我得到的错误。'你的sql syntaxt中有一个错误WHERE name =' jessie'限制1
$ u指的是特定人的数据库中的用户名。如果这不是我怎么能做到这一点?因为$ u在我想从数据库中检索数据时有效。
if(isset($_POST['update'])){
echo $name1=$_POST['name'];
$name1=preg_replace('#[^a-z0-9]#i','',$_POST['name']);
$name1=mysql_real_escape_string($_POST['name']);
echo $surname1=$_POST['surname'];
$name1=preg_replace('#[^a-z0-9]#i','',$_POST['surname']);
$name1=mysql_real_escape_string($_POST['surname']);
echo $company_name1=$_POST['company_name'];
$company_name1=preg_replace('#[^a-z0-9]#i','',$_POST['company_name']);
$compnay_name1=mysql_real_escape_string($_POST['company_name']);
echo $tel_number1=$_POST['tel_number'];
$tel_number1=preg_replace('#[^a-z0-9]#i','',$_POST['tel_number']);
$tel_number1=mysql_real_escape_string($_POST['tel_number']);
echo $cell_number1=$_POST['cell_number'];
$cell_number1=preg_replace('#[^a-z0-9]#i','',$_POST['cell_number']);
$cell_number1=mysql_real_escape_string($_POST['cell_number']);
echo $email1=$_POST['email'];
$email1=mysql_real_escape_string($_POST['email']);
echo $location1=$_POST['location'];
echo $main_image1=$_FILES['main_image']['name'];
echo $main_image_tmp=$_FILES['main_image']['tmp_name'];
$about_us1=$_POST['about_us'];
$about_us=preg_replace('#[^a-z0-9]#i','',$_POST['about_us']);
$about_us=mysql_real_escape_string($_POST['about_us']);
if($name1==""){
echo"<script> alert('Please fill in all the fields & make sure word count is less than 80') </script>";
}else{$moveResult=move_uploaded_file($main_image_tmp,"user/$log_username/".$main_image1);
if($moveResult !=true){
echo " <script>alert('file upload failed , try again') </script> ";
exit();
} else{
$update_query="UPDATE users_info
name='$name1',surname='$surname1',company_name='$company_name1',tel_number='$tel_number1',cell_number='$cell_number1',email='$email1',
location='$location1',main_image='$main_image1',about_us='$about_us1'
WHERE name='$u' LIMIT 1";
if(mysqli_query($connect,$update_query)){
echo " <script>alert('successfully Posted') </script> ";
header('location:user.php?u=$log_username');// redirect to users page or just (index.php)
} else{ echo
"<script>alert('Did not work, try again,please post in all the fields) </script> ";
echo mysqli_error($connect);
}
}
}
?>
<?php } ;} else{ echo " you are not logged in "; header("location:login.php");} ?>
答案 0 :(得分:1)
SET 。
$update_query="UPDATE users_info
SET name='$name1',surname='$surname1',company_name='$company_name1',tel_number='$tel_number1',cell_number='$cell_number1',email='$email1', location='$location1',main_image='$main_image1',about_us='$about_us1' WHERE name='$u' LIMIT 1";