Hi, i've got a changepassword script and i'm trying to get it to say password changed or incorrect password on the same page. But currently any errors open in a new blank page and if it is successful it shows nothing. here is my code, i hope someone can help.
PHP Code:
<?php
session_start();
include ('../scripts/dbinfo.php');
$myusername = $_SESSION['myusername'];
// username and password sent from form
$oldpassword=md5($_POST['oldpass']);;
$newpassword1=md5($_POST['newpass1']);
$newpassword2=md5($_POST['newpass2']);
// To protect MySQL injection (more detail about MySQL injection)
$sql="SELECT * FROM users WHERE username='$myusername' and password='$oldpassword'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if ($count==1 && $newpassword1 == $newpassword2)
{
$changethepassword="UPDATE `users` SET `password`='$newpassword1' WHERE `username`='$myusername'";
mysql_query($changethepassword);
header("location: ../index.php?cmd=changepass");
echo "Password Changed";
}
elseif($myusername=="") //check if user session is empty
{
echo "Not logged in";
include 'login.php';
}
elseif($count==0) // check if password is correct
{
echo "Incorrect password";
include 'changepass.php';
}
elseif ($newpassword1 != $newpassword2) //check if both password fields match
{
echo "passwords did not match";
include 'changepass.php';
}
else // if both are incorrect
{
echo "Pasword incorrect and passwords did not match";
include 'changepass.php';
}
echo "<br/>";
?>