Internal server error when submitting html / PHP form

I am coding a basic web page and one of the requirements is an html form that sends input via a php file.

I encoded the following in an html file:

<form method="post" action="formsubmit.php" name="Contact Form" id="contactform" enctype="multipart/form-data"> <fieldset> <legend align="center"> Your Details </legend> <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label for="fname">First Name: </label> <input type="text" id="fname" required/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label for="sname">Surname: </label> <input type="text" id="sname" required/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label for="email">Email Address: </label> <input type="email" id="email" required/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label for="phone">Phone Number: </label> <input type="tel" id="phone" required/> <br /> <br /> </p> </fieldset> <fieldset> <legend align="center"> Third Parties </legend> <p> <label for="sharedetails">Tick this box if you would like to recieve ticket and event information from our carefully selected third parties.</label> <input type="checkbox" name="sharedetails" value="sharedetailsno" id="sharedetails" /> </p> <p> <input type="submit" value="Submit" /> <input type="reset" value="Clear" /> </p> </fieldset> </form> 

and then created the following php file:

 <html> <head> <title>Process Feedback</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $fname = $_POST["firstname"]; $sname = $_POST["surname"]; $email = $_POST["email"]; $phone = $_POST["phone"]; $sharedetails = $_POST["sharedetails"]; print "test test $fname $sname $email $phone test test"; ?> </body> </html> 

it is obvious that the php file is still in the testing phases, and I want it to return the provided data before formatting it correctly with the correct data output, etc.

but it always returns "Internal Server Error" when submitting the form. I searched the Internet for answers and found similar posts, but none of them helped my problem.

I am using Apache server on local system. Could the problem be incorrect?

If I can get the form data in order to correctly transfer the php file, I can format the remaining html page / output page.

+4
source share
2 answers

You need to have the attributes of the name form on the first page set equal to your elements of the $_POST array on the second page.

This should be your code on the first page:

 <form method="post" action="formsubmit.php" name="Contact Form" id="contactform" enctype="multipart/form-data"> <fieldset> <legend align="center"> Your Details </legend> <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label for="fname">First Name: </label> <input type="text" name="fname" id="fname" required/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label for="sname">Surname: </label> <input type="text" name="sname" id="sname" required/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label for="email">Email Address: </label> <input type="email" name="email" id="email" required/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label for="phone">Phone Number: </label> <input type="tel" name="phone" id="phone" required/> <br /> <br /> </p> </fieldset> <fieldset> <legend align="center"> Third Parties </legend> <p> <label for="sharedetails">Tick this box if you would like to recieve ticket and event information from our carefully selected third parties.</label> <input type="checkbox" name="sharedetails" value="sharedetailsno" id="sharedetails" /> </p> <p> <input type="submit" value="Submit" /> <input type="reset" value="Clear" /> </p> </fieldset> </form> 

This should be the code for formubmit.php:

 <html> <head> <title>Process Feedback</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $fname = $_POST["fname"]; $sname = $_POST["sname"]; $email = $_POST["email"]; $phone = $_POST["phone"]; $sharedetails = $_POST["sharedetails"]; print "test test $fname $sname $email $phone test test"; ?> </body> </html> 
+1
source

Too much mess just use the basics to get started.

Get rid of

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

You are not using identifiers correctly

 $_POST["fname"]; 

instead: $ _POST ["Firstname"];

You need to attach your output and echo them

 echo "test test ".$fname.$sname.$email.$phone."test test"; 
0
source

Source: https://habr.com/ru/post/1438959/


All Articles