Help me wont set!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Help me wont set!

Post by nick2 »

Hello.. I am trying to authenticate a user.. it does what its suppose to up to set cookie.. please look!

Code: Select all

<?php
if ((!$_POST[username]) || (!$_POST[password])) {
 Print("Please hit back button and make sure all the fields are all filled in!");
}

#variables#
$db_address = "localhost";
$db_name = "pixelfriendly_com";
$table_name = "aprilacc";
$db_user = "pixel";
$db_pass = "***";

#connection#
$connection  = @mysql_connect($db_address, $db_user, $db_pass) or die(mysql_error());

#select#
mysql_select_db($db_name) or die(mysql_error());

#
$sql = "SELECT * FROM $table_name WHERE GID = '$_POST[username]'
AND password = password('$_POST[password]')";

#results#
$result = @mysql_query($sql, $connection) or print("The ID or password is incorrect");

$num = mysql_num_rows($result); #think it starts here! the problem!
#
If ($num !=0) {
$cookie_name = "auth";
$cookie_value = "ok";
$cookie_expire = "0";
$cookie_domain = "http://game.pixelfriendly.com";
#
setcookie($cookie_name, $cookie_value, $cookie_expire, "/" , $cookie_domain, 0);
setcookie("user", $_POST[username], $cookie_expire, "/" , $cookie_domain, 0);
header("location: Http://game.pixelfriendly.com/account.php");
#
} else {
header("location: http://game.pixelfriendly.com/errorl.html");
exit;
}
?>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Curious, what does a page with the below give you in result?

Code: Select all

echo '<pre>';
echo 'PHP Version: '.phpversion()."\n";
echo 'Display Errors: '.(ini_get('display_errors') == '1' ? 'On' : 'Off')."\n";
echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
echo '</pre>';
Also, echo out the $sql, $num and other variables before using it, to spot errors. Also, a sidenote, you should try to use $_POST['quotes here'] within the values of $_POST...
Post Reply