Jump to content

Question about $_POST


gammaman

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.