Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 3 in /home/blu6592/public_html/login.php on line 19
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in /home/blu6592/public_html/login.php on line 23
Here is the code that I am working with:
Code: Select all
require "config.php";
// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
$admin_username = trim($admin_username);
$admin_password = trim($admin_password);
$username_check = "SELECT admin_username FROM diary_admin WHERE admin_username='". mysql_real_escape_string($_POST['admin_username']) . "'";
$username_query = mysql_query ($username_check) or die('Query failed. ' . mysql_error());
$username_result = mysql_result($username_query,0);
$password_check = "SELECT admin_password FROM diary_admin WHERE admin_password ='". mysql_real_escape_string($_POST['admin_password']) . "'";
$password_query = mysql_query ($password_check) or die('Query failed. ' . mysql_error());
$password_result = mysql_result($password_query,0);
// Each time there's an error, add an error message to the error array
// using the field name as the key.
if ($_POST['admin_username']=='')
$arrErrors['admin_username'] = 'Please enter your username.';
if ($_POST['admin_password']=='')
$arrErrors['admin_password'] = 'Please enter your password.';
if ($_POST['admin_username'] != $username_result)
$arrErrors['admin_username'] = 'That username was incorrect.';
if ($_POST['admin_password'] != $password_result)
$arrErrors['admin_password'] = 'That password was incorrect.';
if (count($arrErrors) == 0) {
// If the error array is empty, there were no errors.
// Insert form processing here.
print "Login successful. <a href=diary.php>Click here</a> to continue.";
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div><p>';
}
}