deansaddigh Posted April 6, 2010 Share Posted April 6, 2010 $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 https://forums.phpfreaks.com/topic/197757-help-using-session-in-where-clause/ Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 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 https://forums.phpfreaks.com/topic/197757-help-using-session-in-where-clause/#findComment-1037801 Share on other sites More sharing options...
deansaddigh Posted April 6, 2010 Author Share Posted April 6, 2010 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 https://forums.phpfreaks.com/topic/197757-help-using-session-in-where-clause/#findComment-1037803 Share on other sites More sharing options...
conker87 Posted April 6, 2010 Share Posted April 6, 2010 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 https://forums.phpfreaks.com/topic/197757-help-using-session-in-where-clause/#findComment-1037805 Share on other sites More sharing options...
deansaddigh Posted April 6, 2010 Author Share Posted April 6, 2010 Thanks for your help that fixed it Link to comment https://forums.phpfreaks.com/topic/197757-help-using-session-in-where-clause/#findComment-1037808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.