checking login, cookies... help

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
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

checking login, cookies... help

Post by lizlazloz »

Code: Select all

<?php
if ( $_COOKIE[access] == null )
{
header("location:notloggedin.php");
exit();
}
else
{
$sql="select password from game where name= ". $_COOKIE[access] ."
and PASSWORD = password( ". $_COOKIE[passwd] ." )";
echo($sql);
$rs=mysql_query($sql,$conn)
or die("could not execute query");

$num = mysql_numrows($rs);

if($num == 0)
{
header("location:notloggedin.php");
exit();
}
}
?>
cookie access has been set as the username, and cookie passwd is the user's password. it should look thru the DB, and if they both match, all the user to carry on, else goto the not logged in page. i get this error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/tekwar/public_html/checklogin.php on line 12
could not execute query

why?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

By the looks of it it's not a cookie() problem (yet) but a database connection problem. Make sure you are using mysql_connect() and mysql_select_db() correctly... I can't see them in your script anywhere??

If you are only opening one database connection then you shouldn't need to use the $conn variable when you run the query either.

:: [php_man]mysql_connect[/php_man]
:: [php_man]mysql_select_db[/php_man]
dazang
Forum Newbie
Posts: 10
Joined: Tue Aug 30, 2005 2:29 pm
Location: USA
Contact:

Please show your variables

Post by dazang »

Gen-ik's right, it is a mysql connect problem.

Code: Select all

$rs=mysql_query($sql,$conn)
or die("could not execute query");
So if you could please show us the file your $sql & $conn variables are located & why it is not included here?
Post Reply