View Full Version : Using session variables on a form

07-22-2011, 09:38 AM
Hi, I'm a bit new to all this. Let me explain what' I'm currently trying to do...

I have a login page, some standard pages and a page with a form that connects through to a database on it.

I have the login functionality working (using the standard dreamweaver user authentication functionality). I want to be able to use the username of the person who has logged in, in one of the form fields (username field) so that they don't have to type it again.

I presume that the user details are kept in some kind of session parameter, and I need to reference this on the form - but how do I do it!?

The code in the form is:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO predictions (user_id, game_id, game1_home, game1_away, game2_home, game2_away, game3_home, game3_away, game4_home, game4_away, game5_home, game5_away, game6_home, game6_away, game7_home, game7_away, game8_home, game8_away, game9_home, game9_away, game10_home, game10_away, game11_home, game11_away, game12_home, game12_away) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['user_id'], "int"),
GetSQLValueString($_POST['game_id'], "int"),
GetSQLValueString($_POST['game1_home'], "int"),
GetSQLValueString($_POST['game1_away'], "int"),
GetSQLValueString($_POST['game2_home'], "int"),

The line in bold is where I need it to reference the username.

I can post the user authentication code if required (I use the standard dreamwqeaver functionality, and the form page above has the user authentication check code on it) - as I say I'm stumbling my way through this so would really appreciate any help!

Many thanks,