Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-25-2002, 11:01 PM   PM User | #1
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
PHP/MYSQL once logged in check id...

hey,
im trying to get the id form a users table here in mysql/php...
the script works fine. checks username and password etc
and then use a meta refresh to send the id to the next page. tho it just seems to not exstract or print the id at all.. as you`ll see.
Code:
<?php
#login.php
#ensure both form fields have entries
if( (!$username) || (!$password) )
{
header("Location:$HTTP_REFERER");
exit();
}

#connect to MySQL
$conn=@mysql_connect("localhost", "", "")
or die("Could not connect");

#select the specified database
$rs = @mysql_select_db("GAME", $conn)
or die("Could not select database");

#create the query
$sql="select * from user where username='$username' and password ='$password'" ;

#execute the query
$rs=mysql_query($sql,$conn)
or die("Could not execute query");

#get number of rows that match username and password
$num = mysql_num_rows($rs);

#if there is no match go back to log in page
if($num==0)
{
header("Location:loginerror.htm");
exit();}
else
{
#otherwise user is authenticated
$msg = "<h3>Loggin you in $username ...</h3>";
}
?>

<?php
echo("<html><head><title>Log-In blah blah meta be be soon..</title><meta http-equiv='refresh' content='1; 

URL=inside.php?id=$id'></head><body>");
?>

<?php echo($msg); ?>

</body></html>
is it cuz the php tag has been closed and opened again? cuz i changed it so it was like this...
Code:
#otherwise user is authenticated
$msg = "<h3>Loggin you in $username ...</h3>";
}

echo("<html><head><title>Log-In blah blah meta be be soon..</title><meta http-equiv='refresh' content='1; 

URL=inside.php?id=$id'></head><body>");
?>
but that just errored..
anyway any ideas?
thanks
P
sir pannels is offline   Reply With Quote
Old 10-26-2002, 01:09 AM   PM User | #2
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
That's because you send only a query to the database, but don't extract the contents of the result list you get in return. Think of the return value of a succesful mysql_query() as a pointer to a big list of single records. You now have to access each single record and read the values from it's fields.

Assuming that there can only be one possible recordset, I think this might be a quick fix:

PHP Code:
$rs=mysql_query($sql,$conn)
or die(
"Could not execute query");

if (
$rs && mysql_num_rows($rs) > 0) {
$row mysql_fetch_assoc($rs);
$id $row['id'];

Check the manual sections about mysql_fetch_array(), mysql_fetch_assoc(), mysql_fetch_row() and mysql_fetch_object() to get an impression how you can retrieve the single records from a MySQL resource.
mordred is offline   Reply With Quote
Old 10-26-2002, 02:07 AM   PM User | #3
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
ok thanks man
i`ll go add that into the script...
sir pannels is offline   Reply With Quote
Old 10-26-2002, 02:13 AM   PM User | #4
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
it worked perfect
thank you very much
sir pannels is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:05 AM.


Advertisement
Log in to turn off these ads.