更新查询不起作用,并将字段更改为0


update query not working and change fields to 0

我有这个表单代码。

<form action="save_profile.php" method="post">
          <table>
            <tr><td>First Name:</td><td><input type="text" name="fname" value="<?php echo $fname;?>"></td></tr>
            <tr><td>Last Name:</td><td><input type="text" name="lname" value="<?php echo $lname;?>"></td></tr>
            <tr><td>Mail ID:</td><td><input type="text" name="mail" value="<?php echo $mail;?>"></td></tr>
            <tr><td>Contact NO:</td><td><input type="text" name="contact" value="<?php echo $contact;?>"></td></tr>
            <tr><td></td><td><input type="submit" name="submit" value="Save Profile"></td></tr>
          </table>
          </form>

我的save_profile.php文件有这样的代码。

<?php
session_start();
require('config.php');
function is_valid_fname($fname,$lname,$contact)
{
 if (empty($fname)) {
     ?>
     <center><strong><font color="red">First Name is required.</font></strong></center>
     <?php
     return false;
 }
 if ( !preg_match ("/^[a-zA-Z's]+$/",$fname)) {
     ?>
     <center><strong><font color="red">First Name Only Contain Letters.</font></strong></center>
     <?php
     return false;
 } 
 if (strlen($fname)>20) {
     ?>
     <center><strong><font color="red">First Name must be less than 20 Letters.</font></strong></center>
     <?php
     return false;
 }
 if (empty($lname)) {
     ?>
     <center><strong><font color="red">Last Name is required.</font></strong></center>
     <?php
     return false;
 }
 if ( !preg_match ("/^[a-zA-Z's]+$/",$lname)) {
     ?>
     <center><strong><font color="red">Last Name Only Contain Letters.</font></strong></center>
     <?php
     return false;
 } 
 if (strlen($lname)>20) {
     ?>
     <center><strong><font color="red">Last Name must be less than 20 Letters.</font></strong></center>
     <?php
     return false;
 }
 if (empty($contact)) {
     ?>
     <center><strong><font color="red">Contact is required.</font></strong></center>
     <?php
     return false;
 }
 if ( !preg_match ("/^[0-9's]+$/",$contact)) {
     ?>
     <center><strong><font color="red">Contact Only Contain Numbers.</font></strong></center>
     <?php
     return false;
 }
 if (strlen($contact)>15) {
     ?>
     <center><strong><font color="red">Contact must be less than 20 Digits.</font></strong></center>
     <?php
     return false;
 } 
 else{
  return true;
 }
}
function is_valid_email($mail)
{
 if (empty($mail)) {
     ?>
     <center><strong><font color="red">Email is required.</font></strong></center>
     <?php
     return false;
 } else {
     $email = test_input($mail);
     // check if e-mail address is well-formed
     if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
       ?>
     <center><strong><font color="red">Invalid Email Format.</font></strong></center>
     <?php 
       return false;
 } 
 // now check if the mail is already registered
 $slquery = "SELECT 1 FROM user_tbl WHERE user_mail = '".$mail."'";
 $selectresult = mysql_query($slquery);
 if(mysql_num_rows($selectresult)>1) {
   ?>
     <center><strong><font color="red">This Email Is Already Exits.</font></strong></center>
     <?php
   return false;
 }
 // now returns the true- means you can proceed with this mail
 return true;
}
}
if (isset($_POST['submit'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$contact = $_POST['contact'];
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if (is_valid_email($mail) && is_valid_fname($fname,$lname,$contact))
{
    $query="UPDATE user_tbl SET user_fname='".$fname."' AND user_lname='".$lname."' AND user_mail='".$mail."' AND user_contact='".$contact."' WHERE user_id='".$_SESSION['uid']."'";
     $result = mysql_query($query);
     if ($result) {
         header('location:profile.php');
     }
}
else{
      ?>
     <center><strong><font color="red">Error Updating User.</font></strong></center>
     <?php
    }
}
?>

我的问题是,当我更改表单数据时,在表单中显示数据后,当我提交表单时,它将始终更新我的user_fname=0…当我更改其他字段时,我的其他字段保持不变,并将user_fname设置为0。请帮我…

请使用逗号(,(代替

$query="UPDATE user_tbl SET user_fname='".$fname."', user_lname='".$lname."', user_mail='".$mail."', user_contact='".$contact."' WHERE user_id='".$_SESSION['uid']."'";
  "SELECT `1` FROM `user_tbl` WHERE `user_mail` = '".$mail."'"; 
  "UPDATE `user_tbl` SET `user_fname`='".$fname."' AND `user_lname`='".$lname."'AND
  `user_mail`='".$mail."' AND `user_contact`='".$contact."' WHERE 
  `user_id`='".$_SESSION['uid']."'";

你忘了庄重的口音了。现在检查它是否仍然有效。