I am having trouble processing a form in PHP.

The Problem: When I submit the form, I expect to see the data printed on the screen. However, I am sometimes seeing my custom "Denied" error message, or if I fix that, I suspect my radio buttons aren't capturing the data correctly because my PHP looks for $_POST['job'] but my HTML doesn't seem to link the buttons together.

Questions:

Why does my else block trigger ("Denied") sometimes?

How do I correctly structure the HTML radio buttons so they send a single "job" value to PHP?

Here's the form.html:

<!DOCTYPE html> <html lang="tr"> <head> <meta charset="UTF-8"> <title>Form</title> </head> <body> <form name="testform" action="process.php" method="POST"> <table border="1"> <tr> <td>Ad</td> <td><input name="firstname" type="text"></td> </tr> <tr> <td>Soyad</td> <td><input name="lastname" type="text"></td> </tr> <tr> <td>Job</td> <td> <input for="job" name="engineer" type="radio"> Engineer<br> <input for="job" name="teacher" type="radio"> Teacher<br> <input for="job" name="manager" type="radio"> Manager<br> <input for="job" name="mechanic" type="radio"> Mechanic<br> </td> </tr> <tr> <td>Yas</td> <td><input name="age" type="text"></td> </tr> </table> <input type="submit" value="Send"> </form> </body> </html>

Here's the process.php:

<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $firstname = $_POST["firstname"]; $lastname = $_POST["lastname"]; $job = $_POST["job"]; $age = $_POST["age"]; echo "<h2>Formdan Gelen Datalar:</h2>"; echo "Adin: ".$firstname."<br>"; echo "Soyadin: ".$lastname."<br>"; echo "Job: ".$job."<br>"; echo "Age: ".$age."<br>"; } else { echo "Denied"; } ?>

BlackBoxIsGoat's user avatar

New contributor

BlackBoxIsGoat is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.