Page 1 of 1

Logging Cookies

Posted: Fri Jun 13, 2003 10:22 am
by polosport6699
I have written a script to log cookies but I cannot get it to work. Any help??
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>

Posted: Fri Jun 13, 2003 10:25 am
by twigletmac
Please can you edit your posts to add additional information instead of posting a new, additional topic. Also, if you use [syntax=php][/syntax] tags instead of [syntax=php][/syntax] it can make the code easier to read (and less green).

Mac

Posted: Fri Jun 13, 2003 10:56 am
by twigletmac
I've have just deleted a third topic that you have started for the same question. Please add to existing topics and if you can't find your original topic do a search on your username before posting another one.

Mac