el_nino Posted December 30, 2009 Share Posted December 30, 2009 Hey... what I am trying to do is use the information stored in a session to display all the information of the user who has just logged in my script currently looks like... <?php session_start(); // Start the session. // If no session value is present, redirect the user: // Also validate the HTTP_USER_AGENT! if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT']) )) { require_once ('login_functions.inc.php'); $url = absolute_url(); header("Location: $url"); exit(); } ?> <html> <head> <title> My Profile</title> </head> <?php include ('includes\header.html'); ?> <?php //require_once ('mysql_connect.php'); //connect to your database mysql_connect("****","****","****"); //(host, username, password) //specify database mysql_select_db("****") or die("Unable to select database"); //select which database we're using ?> <body> <div align="center"> </br> <?php // Print a customized message: echo "<p>You are logged in as <b>{$_SESSION['Name']}!</b></p>"; ?> <?php //$query = "select * from members where Name = ['Name']"; //$query = "select * from members where Name = '$_SESSION['Name']'"; $query = "select * from members where Name = '" . $_SESSION['Name'] . "'"; //$numresults=mysql_query($query); //$numrows=mysql_num_rows($numresults); // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Could not execute query"); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Username</th> <th>DOB</th> <th>Team</th> <th>Email</th></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['Name']; echo "</td><td>"; echo $row['Username']; echo "</td><td>"; echo $row['DOB']; echo "</td><td>"; echo $row['Team']; echo "</td><td>"; echo $row['Email']; echo "</td></tr>"; } echo "</table>"; ?> </br> </div> </body> <?php include ('\includes\footer.html'); ?> </html> the error i am getting is "Could not execute query" el nino Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/ Share on other sites More sharing options...
jonsjava Posted December 30, 2009 Share Posted December 30, 2009 change $result = mysql_query($query) or die("Could not execute query"); to $result = mysql_query($query) or die("Could not execute query:\n".mysql_error()); and post the results here. Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/#findComment-986023 Share on other sites More sharing options...
el_nino Posted December 30, 2009 Author Share Posted December 30, 2009 right, so after doing that i now get the following error: Could not execute query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 and also get: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\view_profile.php:3) in C:\xampp\htdocs\view_profile.php on line 4 Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/#findComment-986026 Share on other sites More sharing options...
jonsjava Posted December 30, 2009 Share Posted December 30, 2009 try this version: <?php session_start(); // Start the session. // If no session value is present, redirect the user: // Also validate the HTTP_USER_AGENT! if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT']) )) { require_once ('login_functions.inc.php'); $url = absolute_url(); header("Location: $url"); exit(); } ?> <html> <head> <title> My Profile</title> </head> <?php include ('includes\header.html'); ?> <?php //require_once ('mysql_connect.php'); //connect to your database mysql_connect("****","****","****"); //(host, username, password) //specify database mysql_select_db("****") or die("Unable to select database"); //select which database we're using ?> <body> <div align="center"> </br> <?php // Print a customized message: echo "<p>You are logged in as <b>{$_SESSION['Name']}!</b></p>"; ?> <?php //$query = "select * from members where Name = ['Name']"; //$query = "select * from members where Name = '$_SESSION['Name']'"; $query = "SELECT * FROM `members` WHERE `Name` ='{$_SESSION['Name']}'"; //$numresults=mysql_query($query); //$numrows=mysql_num_rows($numresults); // get results $query .= " LIMIT $s,$limit;"; echo $query; $result = mysql_query($query) or die("Could not execute query\n".mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Username</th> <th>DOB</th> <th>Team</th> <th>Email</th></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['Name']; echo "</td><td>"; echo $row['Username']; echo "</td><td>"; echo $row['DOB']; echo "</td><td>"; echo $row['Team']; echo "</td><td>"; echo $row['Email']; echo "</td></tr>"; } echo "</table>"; ?> </br> </div> </body> <?php include ('\includes\footer.html'); ?> </html> it will output your query, so you can check it for errors. Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/#findComment-986028 Share on other sites More sharing options...
el_nino Posted December 30, 2009 Author Share Posted December 30, 2009 i now get: SELECT * FROM `members` WHERE `Name` ='Guest' LIMIT ,;Could not execute query You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 this looks like its correct in that the user that has just logged in is Guest and it is this users details that should be displayed i cant seem to see what is wrong at line 1 Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/#findComment-986029 Share on other sites More sharing options...
jonsjava Posted December 30, 2009 Share Posted December 30, 2009 your limit isn't being set, for some reason. Might want to hard code the limits, if that's possible. Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/#findComment-986087 Share on other sites More sharing options...
el_nino Posted December 31, 2009 Author Share Posted December 31, 2009 ok, i don't quite understand what you mean... could you please elaborate/ give me an example Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/#findComment-986403 Share on other sites More sharing options...
wildteen88 Posted December 31, 2009 Share Posted December 31, 2009 Looking at your code you can just delete this line $query .= " LIMIT $s,$limit;"; It is not needed at all. Or just change it to $query .= " LIMIT 1"; Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/#findComment-986504 Share on other sites More sharing options...
el_nino Posted December 31, 2009 Author Share Posted December 31, 2009 thank you people Link to comment https://forums.phpfreaks.com/topic/186708-sessions-and-mysql-queries/#findComment-986559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.