Page 1 of 1

using $_SESSION to pass table_id

Posted: Fri Nov 26, 2004 12:22 am
by TheOracle
Hi All,

I'm getting stuck when using the $_SESSION variables. I want to set a session variable based on a unique column in a MySQL table.

Can I do this anythinglike this:

Code: Select all

$result=mysql_query("select loan_id from secure_loan 
                            where username = '".$_POST['username']." '  )") 
$_SESSION['uniqueid'] == $result;


If this would work, where abouts in the code would I put it.

Thanks

Different Syntax

Posted: Fri Nov 26, 2004 5:43 am
by thomas777neo
It should look more like this:

Code: Select all

<?php
session_start();
$result=mysql_query("select loan_id from secure_loan  where username = '".$_POST['username']." '  )") 
// change the == to = (you are not comparing anything, you are assigning)
$_SESSION['uniqueid'] = $result;
?>

Another Fix

Posted: Fri Nov 26, 2004 5:48 am
by thomas777neo
In your code you assign $result = mysql_query(...

The result won't return the id. You should actually say something like this:

Code: Select all

<?php
session_start();

$query = mysql_query("select id from table");

$result = mysql_fetch_array($query);
				
$unique_id = $result['id'];

$_SESSION["unique_id"] = $unique_id;
?>