Forum Moderators: coopster

Message Too Old, No Replies

SESSION Variable

         

paseo

6:10 am on Jan 29, 2007 (gmt 0)

10+ Year Member



$_SESSION['value1'] = mysql_real_escape_string($_POST['dt']);

$sql = "INSERT INTO $table (value1) VALUES ("$_SESSION['value1']")"

Something like that doesnt work. Is my syntax incorrect?

cameraman

6:17 am on Jan 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Close - you have to use braces for arrays inside quoted strings (I just got comfortable doing this yesterday; I've avoided it like the plague previously):

$sql = "INSERT INTO $table (value1) VALUES ({$_SESSION['value1']})"

Another way to do it is:
$sql = "INSERT INTO $table (value1) VALUES (" . $_SESSION['value1'] . ")"

Those are both assuming that value1 is numeric. If it's varchar, text, etc. you need quotes:
$sql = "INSERT INTO $table (value1) VALUES ('{$_SESSION['value1']}')"

or
$sql = "INSERT INTO $table (value1) VALUES ('" . $_SESSION['value1'] . "')"

paseo

6:24 am on Jan 29, 2007 (gmt 0)

10+ Year Member



Worked like a champ! Thanks!