Hello,
I've written a code for users to update their username & password. This code interacts with a MySql database. For some reason, the code is not updating the MySql database though there is no error message displayed. I suspect it has got something to do with the following statement I'm using:-
if ((mysql_result($result,0,"email")=='$email')&&(mysql_result $result,0,"password")=='$pass3')){
Anyway, I've posted my full code below for you to see the big picture. I appreciate your guidance on this matter.
<head>
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="">
<p>
<input name="username" type="text" id="username" size="20">
Type a username of your choice </p>
<p>
<input name="password1" type="password" id="password1" size="20">
Type a password of your choice</p>
<p>
<input name="password2" type="password" id="password2" size="20">
Re-confirm password </p>
<p>
<input name="password3" type="password" id="password3" size="20">
Key in your old password
</p>
<p>
<input name="email" type="text" id="email" size="20">
Your registered email address </p>
<p>
<input name="Submit1" type="submit" id="Submit1" value="Submit">
</p>
<p>
<?php
$username="abc123";
$password="abc123";
$database="abc123";
$host="localhost";
$user=$_POST['username'];
$pass1=$_POST['password1'];
$pass2=$_POST['password2'];
$pass3=$_POST['password3'];
$email=$_POST['email'];
$Submit1=$_POST['Submit1'];
if(isset($Submit1))
{
if (($user != '')&&($pass1 != ''))
{
if ($pass1 == $pass2)
{
mysql_connect ("$host","$username","$password");
mysql_select_db($database) or die( "Where's the database man?");
$query = "SELECT * FROM customers WHERE email = '$email' AND password = '$pass3'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows > 0)
{
if ((mysql_result($result,0,"email")=='$email')&&(mysql_result($result,0,"password")=='$pass3'))
{
$query="UPDATE customers SET username = '$user', password = '$pass1' WHERE email='$email' AND password = '$pass3'";
mysql_query($query);
echo "Excellent! Your new username & password have been updated!";
}
else
{
echo "Something's not right somewhere :-)";
}
}
else
{
echo "You are not a registered user";
}
}
else
{
echo "Password does not match";
}
}
else
{
echo "The fields are blank!";
}
}
?>
</p>
</form>
</body>
</html>