php - update query not working and change fields to 0 -
i have form code.
<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>
and save_profile.php file has code.
<?php session_start(); require('config.php'); function is_valid_fname($fname,$lname,$contact) { if (empty($fname)) { ?> <center><strong><font color="red">first name required.</font></strong></center> <?php return false; } if ( !preg_match ("/^[a-za-z\s]+$/",$fname)) { ?> <center><strong><font color="red">first name contain letters.</font></strong></center> <?php return false; } if (strlen($fname)>20) { ?> <center><strong><font color="red">first name must less 20 letters.</font></strong></center> <?php return false; } if (empty($lname)) { ?> <center><strong><font color="red">last name required.</font></strong></center> <?php return false; } if ( !preg_match ("/^[a-za-z\s]+$/",$lname)) { ?> <center><strong><font color="red">last name contain letters.</font></strong></center> <?php return false; } if (strlen($lname)>20) { ?> <center><strong><font color="red">last name must less 20 letters.</font></strong></center> <?php return false; } if (empty($contact)) { ?> <center><strong><font color="red">contact required.</font></strong></center> <?php return false; } if ( !preg_match ("/^[0-9\s]+$/",$contact)) { ?> <center><strong><font color="red">contact contain numbers.</font></strong></center> <?php return false; } if (strlen($contact)>15) { ?> <center><strong><font color="red">contact must less 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 required.</font></strong></center> <?php return false; } else { $email = test_input($mail); // check if e-mail address well-formed if (!filter_var($mail, filter_validate_email)) { ?> <center><strong><font color="red">invalid email format.</font></strong></center> <?php return false; } // check if mail registered $slquery = "select 1 user_tbl user_mail = '".$mail."'"; $selectresult = mysql_query($slquery); if(mysql_num_rows($selectresult)>1) { ?> <center><strong><font color="red">this email exits.</font></strong></center> <?php return false; } // returns true- means can proceed 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."' , user_lname='".$lname."' , user_mail='".$mail."' , user_contact='".$contact."' 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 } } ?>
my problem after displaying data in form when change form data , when submit form update user_fname=0...when change other field other fields remain same , set user_fname=0.please me...
please use comma(,) in stead of and
$query="update user_tbl set user_fname='".$fname."', user_lname='".$lname."', user_mail='".$mail."', user_contact='".$contact."' user_id='".$_session['uid']."'";
Comments
Post a Comment