pixelscape
asked on
Use session variable in a database query
I have a session variable at ... $_SESSION['finish']
Following is part of my database script... using the variable as is does not work... is it because the finish table field and variable name confict? Or do I need to do something with the variable before inserting it?
$result = mysql_query("SELECT * FROM product
WHERE finish='.$_SESSION['finish '].'");
while($row = mysql_fetch_array($result) )
{
echo $row['productcode'] . " " . $row['finish'];
echo "<br />";
}
Following is part of my database script... using the variable as is does not work... is it because the finish table field and variable name confict? Or do I need to do something with the variable before inserting it?
$result = mysql_query("SELECT * FROM product
WHERE finish='.$_SESSION['finish
while($row = mysql_fetch_array($result)
{
echo $row['productcode'] . " " . $row['finish'];
echo "<br />";
}
try this... I think it was a quotes issue...
$result = mysql_query("SELECT * FROM product
WHERE finish= '".$_SESSION['finish'].'") ;
$result = mysql_query("SELECT * FROM product
WHERE finish= '".$_SESSION['finish'].'")
If you echo $_SESSION['finish']; do you see a value?
There is no naming conflict so the problem has to be somewhere else.
You used session_start(); in the beginning of your script?
There is no naming conflict so the problem has to be somewhere else.
You used session_start(); in the beginning of your script?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect... added a double quote to what you wrote and it works fine...
WHERE finish= '".$_SESSION['finish'].'") ;
thx
WHERE finish= '".$_SESSION['finish'].'")
thx
you have to give the same column name in the row index...if finish is ur column name, then it should work.
give a try
Open in new window