gammaman Posted April 18, 2008 Share Posted April 18, 2008 I am having trouble with $POST, Iam trying to send the data within $_POST[], which came from a form, to another page. It is hard for me to explain but here is the code. <body> <?php $Conn=mysql_connect("localhost","fierm","13183"); if(!$Conn){ echo "failed"; } else{ mysql_select_db("fierm"); $User=$_POST["user"]; $Pass=$_POST["pass"]; $result=mysql_query("select studentID, password FROM Student WHERE studentID='$User' and password='$Pass'"); $cou=mysql_num_rows($result); if($cou>0) { echo "<a href=\"student.php?id=$User\">Student Access</a>"; } elseif(($User=="root") && ($Pass=="pwd123")){ echo "<a href=\"admin.php\">Admin Access</a>"; } else{ echo "please go back to the login page"; echo "<br/>"; echo "<a href=\"user.php\">Return to Login</a>"; } } ?> </body> THe code $User=$_POST["user"]; came from a form. The code echo "<a href=\"student.php?id=$User\">Student Access</a>"; is where I am sending it to. And I know it is being sent because on the next page it says id="whatever id number" on the address bar. Here is that page. <body> <b>Student Page</b> <table border = "1"> <b>Registered Courses</b> <tr><th>CourseID</th><th>CourseName</th><th>Drop Course</th></tr> <?php $conn=mysql_connect("localhost","fierm","13183"); if(!$conn){ echo "failed"; }else{ mysql_select_db("fierm"); $Usp=$_POST["id"]; echo "<br/>"; echo "<a href=\"registerCourses.php\">Register Courses</a>"; echo "$Usp"; echo "<br />"; echo "here"; $result=mysql_query("select CourseID,CourseName,StudentID FROM RegCources WHERE StudentID='$Usp'"); $cou=mysql_num_rows($result); echo "$cou"; while($row=mysql_fetch_array($result)) { echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>\n"; } } ?> </table> </body> See this code $Usp=$_POST["id"]; Can I do that. I know it does not work because when I try echo "$Usp"; or $result=mysql_query("select CourseID,CourseName,StudentID FROM RegCources WHERE StudentID='$Usp'"); I get no results. Any help is apprciated. Link to comment https://forums.phpfreaks.com/topic/101710-question-about-_post/ Share on other sites More sharing options...
947740 Posted April 18, 2008 Share Posted April 18, 2008 Assuming you have sessions enabled, they would be a lot easier to use than changing the links. (At least I think so) Try something like this: <?php session_start(); $_SESSION['user'] = $_POST['user']; $_SESSION['pass'] = $_POST['pass']; //Do this for every variable you want passed on ?> Note that you have to start the session on every different page that you want to use the session. Link to comment https://forums.phpfreaks.com/topic/101710-question-about-_post/#findComment-520373 Share on other sites More sharing options...
GameYin Posted April 18, 2008 Share Posted April 18, 2008 Sessions would be best, but for the $Usp, nothing was POSTed Link to comment https://forums.phpfreaks.com/topic/101710-question-about-_post/#findComment-520478 Share on other sites More sharing options...
gammaman Posted April 18, 2008 Author Share Posted April 18, 2008 Are you telling me something should have been posted or are you telling me that nothing was supposed to be posted. My prof will not allow us to use sessions so I need a way for a variable to be sent from a form to a page and then onto another page. Link to comment https://forums.phpfreaks.com/topic/101710-question-about-_post/#findComment-520521 Share on other sites More sharing options...
GameYin Posted April 18, 2008 Share Posted April 18, 2008 Well, if you want to use a post variable, you first have to POST something. So yes, you need to post something. I'm not sure but you could use GET or REQUEST. I don't know much about request so you'll have to research that. Link to comment https://forums.phpfreaks.com/topic/101710-question-about-_post/#findComment-520603 Share on other sites More sharing options...
947740 Posted April 18, 2008 Share Posted April 18, 2008 If you establish a $_POST value, you should be able to access it on the next page. I do not see any problem with that. If you attach information to the URL, you can use the $_GET['varname'] to get the info you want, but that may be impractical with passwords. Link to comment https://forums.phpfreaks.com/topic/101710-question-about-_post/#findComment-520616 Share on other sites More sharing options...
GameYin Posted April 18, 2008 Share Posted April 18, 2008 Hmm, didn't know that little tid bit. I would assume GET would be bad for Pw's, but why again can't you use sessions? If you can't find a solution, maybe try cookies. But they are very insecure. Explain to the person the security benefits of sessions. Link to comment https://forums.phpfreaks.com/topic/101710-question-about-_post/#findComment-520658 Share on other sites More sharing options...
947740 Posted April 18, 2008 Share Posted April 18, 2008 I think he said his professor, assuming that prof means professor, will not let him use sessions, which is interesting, but professors are professors. For one thing, it is very hard (if not impossible?) to reset session data outside the code. They would have to use a form field, figuring out what the $_SESSION['var'] name was. Usually, however, you declare the $_SESSION value after the form data takes place, so they would have to virtually rewrite an entire script in the form field. I would have to agree with the no on cookies. They are very disadvantageous in the fact that they may be turned off in the user's browser, completely destroying any hopes your PHP will work. Link to comment https://forums.phpfreaks.com/topic/101710-question-about-_post/#findComment-520818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.