avincent Posted November 6, 2009 Share Posted November 6, 2009 I am trying to pass a session variable from one page to another, but every time I use the following code you are directed to the right page, but it will not display the content of that page. It seems as if the variable is never making it to that next page. Any suggestions. ---------------------- index.php: <?php session_start(); include "db_connect.php"; if(!isset($_POST['submit'])) { ?> //Display the page here <?php }else{ $user = protect($_POST['user_name']); $pass = protect($_POST['password']); if($user && $pass) { $pass =($pass); //compare the encrypted password $sql="SELECT user_name,company_name FROM `user` WHERE `user_name`='$user' AND `password`='$pass'"; $query=mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($query) > 0) { $row = mysql_fetch_assoc($query); $_SESSION['user_name'] = $row['user_name']; $_SESSION['company_name'] = $row['company_name']; echo "<script type=\"text/javascript\">window.location=\"client-resources.php\"</script>"; } else { echo "<script type=\"text/javascript\"> alert(\"Username and password combination is incorrect!\"); window.location=\"index.php\"</script>"; } } else { echo "<script type=\"text/javascript\"> alert(\"You need to gimme a username AND password!\"); window.location=\"index.php\"</script>"; }}?> ----------------------------------------------------------------------------- redirected page code: <?php session_start(); ?> <div id="main-content"> <?php if(isset($_SESSION['user_name'])) { $user_name = $_SESSION['user_name']; include ("inc/client-resources/client-resources.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/180595-passing-variables-with-windowlocation/ Share on other sites More sharing options...
avincent Posted November 6, 2009 Author Share Posted November 6, 2009 I also put a }else{ echo "nope"; } after the landing page to see if the $_SESSION['user_name']; was set and got the "nope" error Link to comment https://forums.phpfreaks.com/topic/180595-passing-variables-with-windowlocation/#findComment-952808 Share on other sites More sharing options...
avincent Posted November 9, 2009 Author Share Posted November 9, 2009 This is they way the code looks this morning. Still not able to get the variable $_SESSION['user_name'] to pass to the next page. ---------------------- index.php: session_start(); include "db_connect.php"; if(!isset($_POST['submit'])) { //Display the page here }else{ $user = protect($_POST['user_name']); $pass = protect($_POST['password']); if($user && $pass) { $pass =($pass); //compare the encrypted password $sql="SELECT user_name,company_name FROM `user` WHERE `user_name`='$user' AND `password`='$pass'"; $query=mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($query) > 0) { $row = mysql_fetch_assoc($query); $_SESSION['user_name'] = $row['user_name']; $_SESSION['company_name'] = $row['company_name']; echo "<script type=\"text/javascript\">window.location=\"client-resources.php\"</script>"; } else { echo "<script type=\"text/javascript\"> alert(\"Username and password combination is incorrect!\"); window.location=\"index.php\"</script>"; } } else { echo "<script type=\"text/javascript\"> alert(\"You need to gimme a username AND password!\"); window.location=\"index.php\"</script>"; }} ----------------------------------------------------------------------------- redirected page code: session_start(); <div id="main-content"> if(isset($_SESSION['user_name'])) { $user_name = $_SESSION['user_name']; include ("inc/client-resources/client-resources.php"); }else{ echo "nope"; } Link to comment https://forums.phpfreaks.com/topic/180595-passing-variables-with-windowlocation/#findComment-954105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.