Neptunus Maris Posted November 17, 2006 Share Posted November 17, 2006 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 thatThank you in advanceNeptune Link to comment https://forums.phpfreaks.com/topic/27645-cookie-problem/ Share on other sites More sharing options...
jsladek Posted November 18, 2006 Share Posted November 18, 2006 First Print the $row[id] to make sure you have a value thereThen check and see if the cookie is there with a script like this[code]<? // check cookieecho $_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 More sharing options...
Neptunus Maris Posted November 18, 2006 Author Share Posted November 18, 2006 or like this...$userID = $_COOKIE[users];$query = "SELECT * FROM users WHERE id = '$userID'";$result = mysql_query($query) or die(mysql_error());$row = mysql_fetch_array($result) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/27645-cookie-problem/#findComment-126434 Share on other sites More sharing options...
jsladek Posted November 18, 2006 Share Posted November 18, 2006 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 More sharing options...
Neptunus Maris Posted November 18, 2006 Author Share Posted November 18, 2006 Yeah i know i just did a little segment without the braces.Thanks man Link to comment https://forums.phpfreaks.com/topic/27645-cookie-problem/#findComment-126442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.