Displaying error message on the same page !
Posted: Sun Jul 05, 2009 12:51 am
I have a php file named change.php to change the existing password. This page takes username, current password and new password. change.php is directed to verify.php which has to check if the username and current password are correct or not and likewise update it with a new password.
I am unable to load the error message on the same page i.e. change.php and ask the user to try entering again if either the username or existing password are incorrect !
How can this be done? I want to load the error message on page change.php and ask user to enter again !
change.php :
<form name="form1" method="post" action="verify.php">
<input name="userid" type="text" size="9" maxlength="9">
<input name="oldpassword" type="password" size =20" value="" maxlength="20" autocomplete="off" >
<input name="newpassword" type="password" size="20" value="" maxlength="20" autocomplete="off">
<input type="submit" name="Submit" id="Submit" value="Submit">
</form>
verify.php :
<?php
session_start();
$username =$_POST['userid'];
$oldpwd = $_POST['oldpassword'];
$newpwd = $_POST['newpassword'];
$user = "root";
$host = "localhost";
$pswd = "project";
$dbname = "project" ;
mysql_connect($host,$user,$pswd);
mysql_select_db($dbname);
$query = "SELECT password from tbluserentry where username = '$username';";
$result= mysql_query($query);
$passwordhash = md5($oldpwd);
for ($i=0 ;$i<mysql_num_rows($result); $i++)
{
$row_array = mysql_fetch_row($result);
for($j=0 ;$j<mysql_num_fields($result); $j++)
{
if(($row_array[$j]) == $passwordhash)
{
$query = "update tbluserentry set password= md5('$newpwd') where username='$username';";
$result= mysql_query($query);
$_SESSION['global'] = 1;
header( 'Location: update.php' ) ;
}
else
header( 'Location: change.php' ) ;
}
}
?>
Please help me !
I am unable to load the error message on the same page i.e. change.php and ask the user to try entering again if either the username or existing password are incorrect !
How can this be done? I want to load the error message on page change.php and ask user to enter again !
change.php :
<form name="form1" method="post" action="verify.php">
<input name="userid" type="text" size="9" maxlength="9">
<input name="oldpassword" type="password" size =20" value="" maxlength="20" autocomplete="off" >
<input name="newpassword" type="password" size="20" value="" maxlength="20" autocomplete="off">
<input type="submit" name="Submit" id="Submit" value="Submit">
</form>
verify.php :
<?php
session_start();
$username =$_POST['userid'];
$oldpwd = $_POST['oldpassword'];
$newpwd = $_POST['newpassword'];
$user = "root";
$host = "localhost";
$pswd = "project";
$dbname = "project" ;
mysql_connect($host,$user,$pswd);
mysql_select_db($dbname);
$query = "SELECT password from tbluserentry where username = '$username';";
$result= mysql_query($query);
$passwordhash = md5($oldpwd);
for ($i=0 ;$i<mysql_num_rows($result); $i++)
{
$row_array = mysql_fetch_row($result);
for($j=0 ;$j<mysql_num_fields($result); $j++)
{
if(($row_array[$j]) == $passwordhash)
{
$query = "update tbluserentry set password= md5('$newpwd') where username='$username';";
$result= mysql_query($query);
$_SESSION['global'] = 1;
header( 'Location: update.php' ) ;
}
else
header( 'Location: change.php' ) ;
}
}
?>
Please help me !