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?

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'];
...

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.