Jump to content

help using session in where clause


deansaddigh

Recommended Posts

$id = $_GET["id"];
		session_register("id");




		$query = "SELECT * FROM faq WHERE faq_id = '$_SESSION["id"]";
				$result = mysql_query($query, $conn) 
					or die('Error, query failed');		

 

My session in the where clause wont work

 

any help would be appreciated

 

Thanks in advance

Link to comment
Share on other sites

at the top of all scripts using $_SESSION data: session_start();

 

$_SESSION['id'] = mysql_real_escape_string(trim($_GET['id'])); (if id is a string)

-OR-

$_SESSION['id'] = (int) trim($_GET['id']); (if id is an integer)

 

Regarding session_register(): "This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged."

Link to comment
Share on other sites

Thanks you very much i have changed it per your instructions.

How can i put it in my where clause

 

$query = "SELECT * FROM faq WHERE faq_id = '$_SESSION["id"]";
				$result = mysql_query($query, $conn) 
					or die('Error, query failed');		
		while($row= mysql_fetch_array($result))

 

thanks again

Link to comment
Share on other sites

And don't forget to encase the $_SESSION['id'] in {}

$query = "SELECT * FROM faq WHERE faq_id = '{$_SESSION['id']}'";
$result = mysql_query($query, $conn) or die('Error, query failed');

 

I also noticed you missed a ' at the end of the query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.