DOH I dont have a clue

From: Date: Wed, 16 Aug 2000 05:49:26 +0000
Subject: DOH I dont have a clue
Groups: php.db 
Request: Send a blank email to php-db+get-2074@lists.php.net to get a copy of this message
Please explain why this code sets the value "2" into the cookie "userID"REGARDLESS of the values entered into the first two variables? In the table (MySQL) 'users' the field 'id' is a unique key, auto-incrementing but even if I change it to search for a different non interger field like first_name the value returned is 2 when I use this code the same query syntax select id from users where username = 'darkjedi' and password = 'lightsaber'; seems to produce the correct 'id' data (when I issue it directly ( not via PHP) but the value is ALWAYS 2 regardless of what username and password I put into the code I'm totally stumped ######################### <SCRIPT language=php> $username ="darkjedi"; $password ="lightsaber"; ### store SQL in variable get_ID $get_ID = "select id from users where username = '$username' and password = '$password'"; ## open database connection $db = mysql_connect("localhost","secret","verysecret")or die("<br>Died at connect, please try later"); ## select database mysql_select_db(retrieversports_net,$db)or die("<br>Croaked at database selection."); ## do query $sql_id = mysql_query($get_ID,$db) or die ("<center><h4>dead at query. </h4></center>"); setcookie("userID","$sql_id",time()+800,"/",".retrieversports.net",0); echo "<center><h6>debugging text is printed here</h6></center>"; echo "<br> you are user number $sql_id"; </SCRIPT>

« previous php.db (#2074) next »