提交html / PHP表单时出现内部服务器错误

时间:2012-10-10 16:03:24

标签: php html html-form internal-server-error

我正在编写一个基本网页,其中一个要求是一个通过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>
                &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>

然后创建以下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页面/输出页面的其余部分。

2 个答案:

答案 0 :(得分:1)

您需要在第一页上设置name个属性,等于第二页上的$_POST数组元素。

这应该是您的代码的第一页:

<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> 

这应该是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>  

答案 1 :(得分:0)

太多的混乱只是从基础开始。

摆脱

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

您没有正确使用ID

$_POST["fname"];

代替:     $ _POST [ “名字”];

您需要加入输出并回显它们

echo "test test ".$fname.$sname.$email.$phone."test test"; 
相关问题