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>"; } } ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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.