Cannot update the database table using php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • notfound
    New Member
    • Jun 2012
    • 28

    Cannot update the database table using php?

    Here is my part of php code.In this code when a user clicks the edit EditProfile.php is opened.And when the user change his or her info and type the button update the info is coming from the form.However I cannot see the updated info in phpmyadmin.Also the birthday is return as 0000-00-00.I coulndn't understand.Plea se help me.


    Code:
    <?php
    	session_start();
    	
    	include "validate.php";
    	include "src/header.php";
    	include "src/mainmenu.php";
    
    ?>
    <?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 does not match. Try again</a>';
    		echo '<p><a href="EditProfile.php">Try again</p>';
    		include "src/footer.php";
    		exit;
    	}
    	//If the name and the other fields are 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 the 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)."'
           					 WHERE 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 * from users where 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
    
    }
    ?>
    Attached Files
    Last edited by acoder; May 17 '13, 03:37 PM. Reason: Please use [code] tags when posting code
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    As far as I can tell. None of your variables are populated.

    Comment

    • notfound
      New Member
      • Jun 2012
      • 28

      #3
      @Rabbit how can i change it to populate?Could you look at the attached file?

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Sorry, I don't download attachment's from strangers. Please post all relevant code in the thread itself.

        Comment

        • notfound
          New Member
          • Jun 2012
          • 28

          #5
          @Rabbit Ok I have edited my question.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            In your SQL you're missing a quote around your password.

            Comment

            Working...