PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Edit: Note to self. {$happiness['happy']} Use brackets and stuff.
>>Heyo... So I got around to making the cookie login, and it logs in all fine, and sets the cookie. What I'm having a problem with is, is taking info from the cookie and displaying it correctly. The result turns up blank; won't show up in the table.
$user = $_COOKIE['user'];
$query = mysql_query("SELECT * FROM user WHERE username='$user'");
$displayuser = mysql_fetch_array($query, MYSQL_ASSOC);
If I echo $user, it equals the value correctly; that's not a problem. Also, even if I remove ,mysql_assoc after $query, it's the same thing. When I echo it, it just gives me "Array".
<?php
// Set the value of $user to the cookie value 'user'
/**
* SIDE NOTE: What happens if this cookie is not set?
* Methinks you might get familiar with the undefined
* index notice...
*/
$user = $_COOKIE['user'];
// Retrieve a query result identifier from a SQL command
/**
* SIDE NOTE: What happens if there is a issue with the SQL?
* Methinks looking into mysql_error() might be useful.
*
* SIDE SIDE NOTE: You might want to spend some time on
* reserved field names in MySQL and look at the backtick
* (`) escape symbol.
*/
$query = mysql_query("SELECT * FROM user WHERE username='$user'");
// Read the result of the previous query into an associative array
/**
* Since this is an array, you will not be able to echo it out directly.
* However, you could loop over it and get information about it
* that way.
*
* Methinks that the for(), foreach() and while() constructs might be
* useful to you in this situation...
*/
$displayuser = mysql_fetch_array($query, MYSQL_ASSOC);
?>