I keep getting this error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\jobcentral\login.php on line 25
Code: Select all
<? # 7.1 - login.php
$u="username";
$p="password";
$message="Failed";
if (isset($_POST['submit'])) {// Handel Form
require_once ('includes/mysqlconnect.php'); //connect to database
//Create function to escape data
function escape_data ($data) {
global $dbc; // Need the connection
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} //End of function
$message = NULL; // New Variable
// Get user_id and first_name from username password combination
$query = "SELECT user_id and first_name FROM users WHERE username ='$u' AND password=PASSWORD('$p')";
$result = @mysql_query ($query); //Run Query
$row = mysql_fetch_array ($result, MYSQL_NUM); //Return Record
if ($row) { //Record pulled from database
setcookie ('first_name', $row[1]);
setcookie ('user_id' , $row[0]);
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php");
exit();
} else {
$message .= '<p>Does not Match record on file</p>';
}
mysql_close();
}else{
$message .= '<p>Please Try Again.</p>';
}
// End of main submit conditional
// Set the page title and include the html header
$page_title = 'Login';
//Print error message if there is one
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>
<form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter Your Information in the Form Below:</legend>
<p><b>User Name:</b> <input type="text" name"username" size="10" maxlength="20" value="<?php
if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
<p><b>Password:</b><input type="password" name="password" size="20" maxlength="20" /></p>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
</form>