mysql - why cannot be updated data in database table using php? -


here php code.in code if user edits his/her information , clicks update button, posted values must updated in database side.my table name user users.but when want post values name updated not others.and date changed 0000-00-00.why happen?i couldn't understand.any idea , reply helpful?

<?php if(isset($_post['update'])) {   include("db.php");  $name = $_post['name'];  $password1 = md5($_post['password1']); $password2 = md5($_post['password2']); $date_of_birth = $_post['date_of_birth']; $place_of_birth = $_post['place_of_birth']; $info = $_post['info']; $nationality = $_post['nationality'];     echo $_post['name'];    echo $name;    echo $date_of_birth;    echo $info;    echo $place_of_birth;    echo $nationality;  if ($password1 != $password2) {     include "src/header.php";     include "src/mainmenu.php";     echo '<p>error: password not match. try again</a>';     echo '<p><a href="editprofile.php">try again</p>';     include "src/footer.php";     exit; } //if name , other fields empty if($name=='' || $email=='' || $password1=='' || $password2=='' || $date_of_birth==            ''|| $place_of_birth==''|| $info=='' || $nationality=='' ){     include "src/header.php";     include "src/mainmenu.php";     echo '<p>error:you didn\'t fill fields.try again</a>';     echo '<p><a href="editprofile.php">try again</p>';     include "src/footer.php";     exit; }      $email=$_session['email'];     $sql = "update users set name='".mysql_real_escape_string($name)."',                      info=         '".mysql_real_escape_string($info)."',     password=".mysql_real_escape_string($password2)."'     place_of_birth='".mysql_real_escape_string($place_of_birth)."',     date_of_birth='".mysql_real_escape_string($date_of_birth)."',      nationality='".mysql_real_escape_string($nationality)."'                      email ='$email'";     $retval = mysql_query($sql,$link);      if (!$retval|| $retval==false) {     include "src/header.php";     include "src/mainmenu.php";     die('could not update data: ' . mysql_error());     echo '<p><a href="editprofile.php">try again</a></p>';     include "src/footer.php";     mysql_close($link);     exit; } else {     echo "updated data successfully\n";      //header('location: private.php'); }    mysql_close($link);   }  else  {  include("db.php");    $email=$_session['email'];  $run = mysql_query("select * users email='$email'") or die("error!");  $read = mysql_fetch_assoc($run);   ?>  <form method="post" action="<?php $_php_self ?>"> <fieldset> <legend>update profile</legend> <p>     <label for="name">full name:</label> <input type="text" name="name"       id="name" value="<?php echo $read['name']; ?>"/>  <br>     <label for="email">email:</label> <input type="email" name="email"     id="email" value="<?php echo $read['email']; ?>"/>  <br>     <label for="password1">password:</label> <input type="password"      name="password1" id="password1" /> <br>     <label for="password2">confirm password:</label> <input type="password"    name="password2" id="password2" /> <br>     <label for="date_of_birth">date of birth (yyyy-mm-dd):</label> <input   type="date" name="date_of_birth" id="date_of_birth"  value="<?php echo  $read['date_of_birth']; ?>"/> <br>     <label for="place_of_birth">place of birth:</label> <input type="text"    name="place_of_birth" id="place_of_birth" value="<?php echo $read['place_of_birth']; ?  >"/> <br>     <label for="info">information:</label> <textarea name="info" id="info"  rows="5" cols="50" ></textarea> <br>     <label for="nationality">nationality:</label> <input type="text"    , name="nationality" id="nationality" value="<?php echo $read['nationality']; ?>"/> </p>  <p class="center"><input value="update" type="submit" name="update" id="update"/>    </p> </fieldset> </form> <?php  } ?> 

your code wrong in here;

password=".mysql_real_escape_string($password2)."' 

change this;

password='".mysql_real_escape_string($password2)."', 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -