Quesiton about $_POST
Posted: Fri Apr 18, 2008 11:40 am
I am trying to send something from one page to another using the POST method but the second page only receives it in the address bar and not in the variable it is assigned to on the second page.
The first page.
The second page
The first page.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Change A Department</title>
</head>
<?php
?>
<body>
<form action="" method="post">
User Name:<input name="user" type="text"><br />
Password:<input name="pass" type="text"><br />
<br />
<input name="Submit1" type="submit" value="submit" /><br />
</form>
</body>
</html>
<body>
<?php
$Conn=mysql_connect("localhost","fierm","13183");
if(!$Conn){
echo "failed";
}
else{
mysql_select_db("fierm");
$User = $_POST['user']; //recieves a value of one
$Pass = $_POST['pass']; //Not yet used
$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\">StudentPage</a>";
}
elseif(($User=="root") && ($Pass=="pwd123")){
echo "<a href=\"admin.php\">Admin Access</a>";
}
else{
// echo "Invalid Password";
}
}
?>
</body>
Code: Select all
<?php
$U=$_POST[$User];
echo $U //does not print anything but should print one
$conn=mysql_connect("localhost","fierm","13183");
if(!$conn){
echo "failed";
}
else{
mysql_select_db(fierm);
echo "<table border=\"1\">";
echo "<b>Registered Courses</b>";
echo "<tr><th>CourseID</th><th>CourseName</th><th>Drop Course</th></tr>";
$result=mysql_query("select CourseID,CourseName,StudentID FROM RegCources WHERE StudentID='$U'");
$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";
}
echo "</table>";
}
?>