I am writing this script for a time clock and one of the if statements are not working correctly. I have included the file below. I have changed some parts for privacy. It is when it checks to see if the username and current password are correct. The process executes correctly, but it is displaying incorrectly. It always says "Sorry, the username/password combination was not found. You must re-login now. It should say that the password was changed. This is the part of the code that is wierd. Any help is appreciated.
$sql = "SELECT * FROM tc_users WHERE userid = '$user_value' and password = '$current_pass'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0) {
echo "Sorry, that username/password combination was not found. You must re-login now.";
} else {
if ($other_new_pass_value != $other_new_pass_confirm_value) {
echo "Those passwords do not match, please go back and try again.";
}else {
echo "Password has successfully been changed. You must now re-login.";
}
}
Also, I am trying to put that button on the bottom of the page. Is there a way to nest html into a php file without closing the php tags?
<head>
<title>Login Script</title>
<body bgcolor="#9966FF">
<link rel="icon" type="image/ico" href="favicon path"/>
</head>
<?php
define('DB_NAME', 'name');
define('DB_USER', 'user');
define('DB_PASSWORD', 'pass');
define('DB_HOST', 'host');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link){
die('Could not connect: ' .mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}else
$user_value = $_POST['youruserid'];
$current_pass = $_POST['currentpass'];
$new_pass = $_POST['newpass'];
$new_pass_c = $_POST['confirmnewpass'];
$updatesql= "UPDATE tc_users SET password='$new_pass' WHERE userid = '$user_value'";
$updatequery = mysql_query($updatesql);
$sql = "SELECT * FROM tc_users WHERE userid = '$user_value' and password = '$current_pass'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0) {
echo "Sorry, that username/password combination was not found. You must re-login now.";
} else {
if ($other_new_pass_value != $other_new_pass_confirm_value) {
echo "Those passwords do not match, please go back and try again.";
}else {
echo "Password has successfully been changed. You must now re-login.";
}
}
mysql_close();
?>
<form action="login path" method="post" />
<input type="submit" value="Okay." />
</form>
Here is the form that the user submits.
<head>
<title>Change User Password</title>
<body bgcolor="#9966FF">
<link rel="icon" type="image/ico" href="ico path"/>
</head>
<h3>This is the page to change your password.</h3>
<br>
<form action="chgpassprocess.php" method="post" />
<table>
<tr>
<td align="right">Your User ID: </td>
<td align="left"><input type="text" name="youruserid"/></td>
</tr>
<tr>
<td align="right">Current Password: </td>
<td align="left"><input type="password" name="currentpass"/></td>
</tr>
<tr>
<td align="right">New Password: </td>
<td align="left"><input type="password" name="newpass"/></td>
</tr>
<tr>
<td align="right">Confirm New Password: </td>
<td align="left"><input type="password" name="confirmnewpass"/></td>
</tr>
<tr>
<td align="right"><input type="submit" value="Submit" /></td>
<td align="left"><input type="reset" value="Reset Form" /></td>
</tr>
</table>
</form>
<form method="GET" action="path">
<input type="submit" value="Cancel">
</form>