Jump to content

COOKIE problem


Neptunus Maris

Recommended Posts

Hi guys...

I have a problem getting data from cookies.

for example:
[code=php:0]
//I have this segment on my login.php
$query = "SELECT * FROM users WHERE username = '$_POST[username]' AND password = '$_POST[password]'";
$result = mysql_query($query) or die(mysql_error());

//then further down the road when the mysql_num_rows are correct and stuff i set the cookie like this
$row = mysql_fetch_array($result) or die(mysql_error());

setcookie("users", $row[id], time()+1800, "/", 0);
//END
?>
[/code]
Now when a user wants to view his/her profile i want to display their stats or whatever.

For example:
[code=php:0]
if (isset($_COOKIE[users])) {
    //I dont know what to do next.
 
    //then skip to the next step of bringing up the data from the database
    $query = "SELECT * FROM users WHERE (this part N/A until i can get the step above)
    $result = mysql_query($query) or die(mysq_error());
    $row = mysql_fetch_array($result) or die(mysql_error());
[/code]
//then bring up there profile stuff in a table or something

....<td>$row[age]</td>  <---stuff like that


Thank you in advance
Neptune
Link to comment
https://forums.phpfreaks.com/topic/27645-cookie-problem/
Share on other sites

First Print the $row[id] to make sure you have a value there

Then check and see if the cookie is there with a script like this

[code]
<? // check cookie
echo $_COOKIE['users'];
?>
[/code]

The Cookie has to be written between the Header Tags of the HTML when setting it...

I've ran into this when I was not setting a cookie there and it worked untill my page grew, then it became and issue.

-John
Link to comment
https://forums.phpfreaks.com/topic/27645-cookie-problem/#findComment-126430
Share on other sites

I guess I'm not sure about the problem.  Is this ...
[code]if (isset($_COOKIE[users])) [/code]
... not allowing the code in the braces to execute because the cookie is not set or are you just not sure how to query and display the information once you get there?

-John

Link to comment
https://forums.phpfreaks.com/topic/27645-cookie-problem/#findComment-126441
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.