changing password in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tomex
    New Member
    • Feb 2010
    • 6

    #1

    changing password in php

    i have a code in php that changes password. it runs smoothly no errors, but the question is it does not update the passoord on the database??

    here is the form $s is the session ID

    Code:
    <?php echo"
    <form action = \"chpw.php?d='$s'\" method = 'POST'>
    NEW PASSWORD: <input type='text' name='pass'>
    <br/>
    <input type='submit' value='Submit Password'><br/>
    </form>"; ?>

    here is the script that updates

    Code:
    <?php
    
    //$password = md5($_POST['pass']);
    //$s=$_GET['d'];
    //$s=$_POST['id'];
    
    if(md5($_POST['pass'])== ''){
    echo ('invalid password');
    }else
    $sql="UPDATE account SET Password='".md5($_POST['pass'])."' WHERE StudId='".$_GET['d']."'";
    $result=mysql_query($sql);
    	if (!$result)
    		die('Error: ' . mysql_error());
    
    echo "Password Changed Successfully!<br><br>\n";
    header('location: pwlogout.php');
    exit();
    
    ?>
    i have tried anything and still to no avail please help thank you
  • chathura86
    New Member
    • May 2007
    • 227

    #2
    im not sure what you meant by

    here is the form $s is the session ID
    is it the PHP session id? if so you are using the php session id as the
    StudId. so probably that is not right.

    and it is not ok and (not useful) to echo something before the header()
    so remove the header()
    Code:
    echo "Password Changed Successfully!<br><br>\n";
    header('location: pwlogout.php');
    exit();
    and your if condition is not properly written

    do not check the md5 converted string is empty because it will never be.

    and the else condition is not well planned. use { (curly braces) properly



    anyway please edit you script in the following way

    Code:
    <?php
     
    //$password = md5($_POST['pass']);
    //$s=$_GET['d'];
    //$s=$_POST['id'];
     
    if($_POST['pass']== '')
    {
    	echo ('invalid password');
    }
    else
    {
    	$sql="UPDATE account SET Password='".md5($_POST['pass'])."' WHERE StudId='".$_GET['d']."'";
    	
    	echo $sql;
    	
    	$result=mysql_query($sql);
        if (!$result)
            die('Error: ' . mysql_error());
     
    	echo "Password Changed Successfully!<br><br>\n";
    	//header('location: pwlogout.php');
    	exit();
    }
    ?>
    and check the sql which was generated, see if all the variables are
    replaced properly and the way you wanted

    paste the result here if you can so i can analyse it.

    Regards
    Chathura Bamunusinghe

    Comment

    • tomex
      New Member
      • Feb 2010
      • 6

      #3
      Your right i should not use the session[member_if] thanks by the way you did a pretty good help. More power

      Comment

      Working...