anotherphpnoob Posted August 4, 2010 Share Posted August 4, 2010 As the title says session, post and get are not working. This is what i use to initialize them. For get just switch session with get. foreach ($row as $val) { $_SESSION[$rowcount] = $val; // echo "<td>$val</td>\n"; $rowcount=$rowcount+1; } when i was using session i would check to make sure that they were working with a couple of these lines in the same php document. echo "Session row 1 = ".$_SESSION[0]."<br />"; echo "Session row 2 = ".$_SESSION[1]."<br />"; then on the next page where I was trying to receive the variables i was using this just to start off with and make sure i was getting the variables. session_start(); if(!isset($_SESSION[1])){ echo "help1";}else{$var=$_SESSION[1]; } echo $_SESSION[1]; echo $var; if i switch to post and get i get the same results. if there is an easier way to pass variables between pages id love to hear them Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/ Share on other sites More sharing options...
Pikachu2000 Posted August 4, 2010 Share Posted August 4, 2010 What exactly are you trying to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1094859 Share on other sites More sharing options...
anotherphpnoob Posted August 4, 2010 Author Share Posted August 4, 2010 I'm taking information from a database and i want to bring it to a new page where i can access it. The database connection, settings and what not are fine. Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1094863 Share on other sites More sharing options...
Pikachu2000 Posted August 4, 2010 Share Posted August 4, 2010 I think you're going to need to post more code. Can you post the 2 scripts that you posted parts of above? Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1094874 Share on other sites More sharing options...
anotherphpnoob Posted August 4, 2010 Author Share Posted August 4, 2010 script.php <?php session_start(); //database server define('db_server', 'localhost'); //user, password, and database variables $db_user = 'user'; $db_password = 'password'; $db_dbname = 'people'; /** * Run MySQL query and output * results in a HTML Table */ function outputQueryResults() { $username=$_POST['name']; $password=$_POST['pass']; $count=0; $rowcount=0; //run a select query $select_query = "SELECT * FROM names WHERE username= '".$username."' AND password = '".$password."'"; $result = mysql_query($select_query); //output data in a table while ($row = mysql_fetch_row($result)) { // echo "<table>\n"; //echo "<tr>\n"; foreach ($row as $val) { $_SESSION[$rowcount] = $val; //echo "<td>$val</td>\n"; $rowcount=$rowcount+1; $count=$count+1; } //echo "</tr>\n"; } if(is_null($row)||empty($row)&& $count==0) { if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) { $uri = 'https://'; } else { $uri = 'http://'; } $uri .= $_SERVER['HTTP_HOST']; header('Location: '.$uri.'/error.html'); }else{ //echo '</table>'; //echo "Session row 1 = ".$_SESSION[0]."<br />"; //echo "Session row 2 = ".$_SESSION[1]."<br />"; //echo "Session row 3 = ".$_SESSION[2]."<br />"; //echo "Session row 4 = ".$_SESSION[3]; if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) { $uri = 'https://'; } else { $uri = 'http://'; } $uri .= $_SERVER['HTTP_HOST']; header('Location: '.$uri.'/index.php'); } } //connect to the database server $db = mysql_connect(db_server, $db_user, $db_password); if (!$db) { die('Could Not Connect: ' . mysql_error()); } else { echo "Connected Successfully...\n"; } //select database name mysql_select_db($db_dbname); //run query and output results outputQueryResults(); //close database connection mysql_close($db) ?> index.php <?php session_start(); if(!isset($_SESSION[1])){ echo "help1";}else{$var=$_SESSION[1]; } echo $_SESSION[1]; echo $var; ?> Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1094890 Share on other sites More sharing options...
Pikachu2000 Posted August 4, 2010 Share Posted August 4, 2010 I'm not so sure the query is actually succeeding. Let's find out, though. $result = mysql_query($select_query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1094908 Share on other sites More sharing options...
anotherphpnoob Posted August 4, 2010 Author Share Posted August 4, 2010 the SQL query is fine. i built the page to show me that it was working. I then commented out all the stuff because i didnt want it to show up and built the rest of the stuff so that when it does work it, $_SESSION gets its variables and then goes to index.php. this code is one </table> short but if you look in the code i posted before its there. // echo "<table>\n"; //echo "<tr>\n"; foreach ($row as $val) { $_SESSION[$rowcount] = $val; //echo "<td>$val</td>\n"; $rowcount=$rowcount+1; $count=$count+1; } //echo "</tr>\n"; } I also tested whether or not $_SESSION was even getting anything from that statement later on in the page, and then proceeded to comment that out as well. //echo '</table>'; //echo "Session row 1 = ".$_SESSION[0]."<br />"; //echo "Session row 2 = ".$_SESSION[1]."<br />"; //echo "Session row 3 = ".$_SESSION[2]."<br />"; //echo "Session row 4 = ".$_SESSION[3]; Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1094931 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2010 Share Posted August 4, 2010 Are you doing this on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php errors would be reported and displayed, such as header errors that would prevent session variables from working? Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1094932 Share on other sites More sharing options...
anotherphpnoob Posted August 4, 2010 Author Share Posted August 4, 2010 error_reporting was set to E_ALL however display_errors was not set to ON. both of these are now set to the following. display_errors = ON error_reporting = E_ALL ran through the scripts as usual, not sure what im looking for, or what should or should not be happening. Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1094941 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2010 Share Posted August 4, 2010 Does a phpinfo() statement show that those two settings actually have those values, in case the php.ini that you are changing is not the one that php is using? Quote Link to comment https://forums.phpfreaks.com/topic/209729-session-post-get-not-working/#findComment-1095054 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.