0

I have set the two following cookie when a user successfully logs in.

$total = mysql_query("SELECT total FROM usersystem WHERE username = '$username'");
setcookie("username", "$username", time()+3600);
setcookie("total", "$total", time()+3600);
header( 'Location: play.php' ) ;
$_SESSION['username'] = $username;

(Username is previously defined and does display when retrieved.)

Then on the page I want to retrieve the information I have the following code:

<?php
include("db.php"); 
echo $_COOKIE["username"] ;
echo $_COOKIE["total"];
if ((isset($_COOKIE["username"])) && (isset ($_COOKIE["total"]))) {
        echo "Welcome " . $_COOKIE["username"] . "!";
		echo "Score: " . $_COOKIE["total"]; }
else {
 ob_start();
 header( 'Location: nogo.php' ) ;
}
?>

Again, username displays correctly and if the cookie is not set, it does redirect to nogo.php. However, where the total should display it simply displays: Resource id #3

Any help where I am going wrong?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by CEVGames
0

it simply displays: Resource id #3

That's because mysql_query() returns exactly that - a resource, NOT the direct value. You have to extract the value explicitly:

$result = mysql_query("SELECT total FROM usersystem WHERE username = '$username'") or die( mysql_error() );
$row=mysql_fetch_assoc($result);
$total = $row['total'];
...
0

Hielo,

Thanks so much. It worked perfectly.

I am really new to all of this and I'm starting to understand it and be able to apply the concepts on my own thanks to this site and great users like you.

Many thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.