using $_SESSION to pass table_id

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!

Moderator: General Moderators

Post Reply
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

using $_SESSION to pass table_id

Post 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
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Different Syntax

Post 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;
?>
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Another Fix

Post 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;
?>
Post Reply