Munali Posted June 14, 2019 Share Posted June 14, 2019 Kindly help. Am a new php programmer and am learning how to HTML form data to a php script. Have tried several times but information on html form never get submitted. For some unknown reasons, the codes are failing . Here are my codes: <html> <head> <title>Form Destination</title> </head> <body> <?php if(isset($_POST['submit'])) { echo "Name: {$_POST['name']} <br/>"; echo "Age : {$_POST['age']} <br/>"; echo "Gender:{$_POST['gender']} <br/>"; echo "Email:{$_POST['email']} <br/>"; } else { echo "Form was not submitted"; } ?> </body> </html> and <html> <head> <title>Form Source</title> </head> <body> <form action="form_destination.php" method="post"> <br/><br/> Name: <input type="text" name="name"/> <br/><br/> Age: <input type="text" name="age"/> <br/><br/> Gender: Male<input type="radio" name="gender" value="male"/> Female<input type="radio" name="gender" value="female"/> <br/><br/> Email: <input type="text" name="email"/> <br/><br/> <input type="submit" value="submit"/> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Barand Posted June 14, 2019 Share Posted June 14, 2019 Your output depends on there being an input with the name "submit". There isn't one. As it is a bad idea to name an input "submit" rely on a button name to check for submissions of data (if you hit return the button name may not be sent depending on the browser) A better approach to test for posted data is if ($_SERVER['REQUEST_METHOD'] == 'POST' ) { // process posted data } 1 Quote Link to comment Share on other sites More sharing options...
Munali Posted June 14, 2019 Author Share Posted June 14, 2019 Thanks for your reply though even this one has failed to work. I need to do more research on this topic. It has given me hell as i can not do my project of submitting form data to mysql database. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 15, 2019 Share Posted June 15, 2019 I see two pieces of code here - an html form and a php script that grabs the inputs from that form. Where is the problem? Quote Link to comment Share on other sites More sharing options...
MPM Posted June 17, 2019 Share Posted June 17, 2019 The challenge with PHP is that you need to understand HTML, PHP and SQL to get anythign useful done and if you are shaky on any of that it is hell to track down problems. Your HTML is shaky and that suggests you might need some more time on that before you move on but having said that your code looks fine apart from the issue already mentioned by Barand. It should work once you remove the if statement. If you want to have another go here is a page I wrote on the subject for 16 year olds. The site was written to be followed start to end but I think the page makes sense on it's own (especially if you follow the link to the place I explained how to create a form. https://www.yourwebskills.com/page.php?page=124 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.