我正在编写一个基本网页,其中一个要求是一个通过php文件提交输入的html表单.
我在html文件中编写了以下代码:
<form method="post" action="formsubmit.php" name="Contact Form" id="contactform" enctype="multipart/form-data"> <fieldset> <legend align="center"> Your Details </legend> <p> <label for="fname">First Name: </label> <input type="text" id="fname" required/> <label for="sname">Surname: </label> <input type="text" id="sname" required/> <label for="email">Email Address: </label> <input type="email" id="email" required/> <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>
然后创建以下php文件:
<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>
很明显,php文件仍处于测试阶段,我只希望它在我正确格式化正确的数据输出之前返回提交的数据
但每当我提交表单时,它都会一直返回“内部服务器错误”.我在互联网上搜索了答案,并找到了类似的帖子,但没有一个帮助我的问题
我在本地系统上运行apache服务器. ¿问题可能是一些错误的配置?
如果我可以将表单数据正确提交到php文件,那么我可以格式化html页面/输出页面的其余部分.
解决方法
您需要在第一页上设置表单名称属性,等于第二页上的$_POST数组元素.
这应该是您的代码的第一页:
<form method="post" action="formsubmit.php" name="Contact Form" id="contactform" enctype="multipart/form-data"> <fieldset> <legend align="center"> Your Details </legend> <p> <label for="fname">First Name: </label> <input type="text" name="fname" id="fname" required/> <label for="sname">Surname: </label> <input type="text" name="sname" id="sname" required/> <label for="email">Email Address: </label> <input type="email" name="email" id="email" required/> <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>
这应该是formsubmit.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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。