gammaman Posted April 24, 2008 Share Posted April 24, 2008 I have a page set up with sessions like this (checkUser.php) <?php $Conn=mysql_connect("localhost","fierm","13183"); if(!$Conn){ echo "failed"; } else{ mysql_select_db("fierm"); echo "here"; session_start(); if (!isset($_SESSION['checkUser']['user'])) { $_SESSION['checkUser']=$_POST; $_SESSION['checkUser']['user']; $_SESSION['checkUser']['pass']; } echo "{$_SESSION['checkUser']['user']}"; echo "{$_SESSION['checkUser']['pass']}"; $result=mysql_query("select studentID, password FROM Student WHERE studentID='{$_SESSION['checkUser']['user']}' and password='{$_SESSION['checkUser']['pass']}'"); $cou=mysql_num_rows($result); if($cou>0) { echo "Student validated"; echo "<br />"; echo "<a href=\"student.php\">Student Page</a>"; } elseif(("{$_SESSION['checkUser']['user']}"=="root") && ("{$_SESSION['checkUser']['pass']}"=="pwd123")){ echo "<a href=\"admin.php\">Admin Page</a>"; } else{ echo "Invalid Password"; echo "<a href=\"main.php\">Login Again</a>"; } } ?> AND This page receieves it (admin.php) <?php $Conn=mysql_connect("localhost","fierm","13183"); if(!$Conn){ echo "failed"; } else{ mysql_select_db("fierm"); session_start(); $_SESSION['checkUser']['user']; $_SESSION['checkUser']['pass']; echo "<a href=\"addCourse.php\">Add Courses</a>"; echo "<br />"; echo "<a href=\"addStudent.php\">Add Student</a>"; echo "<br />"; echo "<a href=\"addGrades.php\">Input Grades</a>"; } ?> But This page does NOT (student.php) <body> <b>Student Login</b> <?php $Conn=mysql_connect("localhost","fierm","13183"); if(!$Conn){ echo "failed"; } else{ mysql_select_db("fierm"); session_start(); $_SESSION['checkUser']['user']; $_SESSION['checkUser']['pass']; echo "{$_SESSION['checkUser']['user']}"; //Nothing is echoed echo "{$_SESSION['checkUser']['pass']}"; //Nothing is echoed $result=mysql_query("select studentID, password FROM Student WHERE studentID='{$_SESSION['checkUser']['user']}' and password='{$_SESSION['checkUser']['pass']}'"); $cou=mysql_num_rows($result); echo "$cou"; if($cou>0) { echo "<table border=\"1\">"; echo "<b>Registered Courses</b>"; echo "<tr><th>CourseID</th><th>CourseName</th><th>Grade</th></tr>"; $result1=mysql_query("select CourseID,CourseName,StudentID,Grade FROM Rcourse WHERE StudentID='{$_SESSION['checkUser']['user']}'"); $cou=mysql_num_rows($result1); while($row=mysql_fetch_array($result1)) { echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[3]</td></tr>\n"; } echo "</table>"; echo "<b>Register For Courses:</b>"; echo "<br />"; echo "<a href=\"regCourse.php\">Register Courses</a>"; echo "<b>Drop a Course:</b>"; echo "<br/>"; echo "<a href=\"dropCourse.php\">Drop a Course</a>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/102729-_sessions-being-passed-to-one-page-but-not-the-other-help/ Share on other sites More sharing options...
pocobueno1388 Posted April 24, 2008 Share Posted April 24, 2008 You need to call session_start(); at the top of all your pages. Link to comment https://forums.phpfreaks.com/topic/102729-_sessions-being-passed-to-one-page-but-not-the-other-help/#findComment-526057 Share on other sites More sharing options...
JasonLewis Posted April 24, 2008 Share Posted April 24, 2008 As pocobueno1388 said, but make sure its at the VERY top of the page. THE ABSOLUTE top. Link to comment https://forums.phpfreaks.com/topic/102729-_sessions-being-passed-to-one-page-but-not-the-other-help/#findComment-526062 Share on other sites More sharing options...
gammaman Posted April 24, 2008 Author Share Posted April 24, 2008 Yeah I did that already, but now something weird happens, sometimes it works and sometimes it does not, is that even possible? Link to comment https://forums.phpfreaks.com/topic/102729-_sessions-being-passed-to-one-page-but-not-the-other-help/#findComment-526063 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.