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!
I'm trying to show a users name from the database on a page within a members area of the site.
This is what I've got going so far. A connection to the database, a variable $username that stores the users username and a sql query for the persons name.
use sessions to store the information instead of a cookie (less dangerous, more often) .. at any rate, you need to put quotes around $username in your query string (and properly escape it)
<?
// Use sessions, include this on all sessioned pages
session_start();
include_once('/usr/home/fss/websites/fivestarsports.net/inc/func.inc.php');
// Replace COOKIE var with SESSION var
//$username = $HTTP_COOKIE_VARS['log']['username'];
/*
* THIS ASSUMES THE SESSION VAR WAS SET PRIOR TO THIS
*/
$username = $_SESSION['username'];
$db_conn = five_connect_db();
mysql_select_db('fivestar',$db_conn);
$query = "select fname from registered_mem where username = $username";
$result=mysql_query($query);
while ($my=mysql_fetch_array($result))
{
echo "My Fname is " . $my['fname'] . "<br />\n";
echo "My username is $username.<br />\n";
}
?>