Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialkrishna sapkal
Courses Plus Student 62 Pointswhy post is not sending data?
hers the code <!DOCTYPE html>
<?php
$pageTitle="Welcome";
include ("inc/header.php");
?>
<section > <form>
<h3>Enter ID or Rollno</h3>
<input type="text" name="user_rollno" >
<h3>Enter Password </h3>
<input type="password" name="user_password" >
<p>
<a href="feedback.php" > <button type="submit" formmethod="post" formaction="teachers_part.php">Teacher</button></a>
<a href="feedback.php" > <button type="submit" formmethod="post" formaction="feedback.php">Student</button></a>
</form>
</section>
<?php include ("inc/footer.php"); ?>
2 Answers
Matthew Bilz
15,829 PointsHi there,
In your <form> tag, you need to put an action and a method. The action will tell the page where to go when you hit a submit button (i.e., process.php or load_value.php, anything like that, wherever you want it to go) and the method will determine whether the values in your form are submitted via POST or GET.
So, this should do the trick and transfer any values with a 'name' associated to them to your 'action' page:
<form action="wherever_you_want.php" method="post">
//all of your code
<input type="submit" value="submit">
</form>
Matthew Bilz
15,829 PointsOK, but just for your reference, I don't believe that you can have a form within a form. You need to have all of your ducks in a row, so to speak, before you plan out your form and submit actions. So here's what I think would be the easiest thing to do in your PHP form ---
Have a single form and submit button and link that to a form validation to determine if the user is a teacher or a student, then direct the user to the appropriate page via an if/else conditional using different header("Location:ex.teacher.php") rules. Does this make sense?
What I would do is have a boolean column with my users something like 'isTeacher' or 'isStudent', then search for that parameter in my conditional. So, something like:
<?php
$user_rollno = $_POST['user_rollno'];
//Note --- ALWAYS filter input, so if you're using a mysqli database, you would have $user_rollno = mysqli_real_escape_string($db_connection, $_POST['user_rollno']) OR use a PHP sanitize filter, which you can find on php.net
Then find them in your array of users, I'll assume a MySQL database using procedural PHP:
$query = "SELECT * FROM users WHERE user_rollno = $user_rollno;";
$result = mysqli_query($db_connection, $query);
$row = mysqli_fetch_array($result);
$isTeacher = $row['isTeacher'];
if($isTeacher) {
header("Location:teacher_page.php");
} else {
header("Location:student_page.php");
}
?>
And you can set any queries in the URL to direct them to specific pages or whatnot.
Does this help?
krishna sapkal
Courses Plus Student 62 Pointsyup thank you
krishna sapkal
Courses Plus Student 62 Pointskrishna sapkal
Courses Plus Student 62 PointsI want two submit buttons
krishna sapkal
Courses Plus Student 62 Pointskrishna sapkal
Courses Plus Student 62 PointsAnd i want to link the submit button to another page..you cant link the input type it will only submit the data