4

我正在编写一个基本网页,其中一个要求是通过 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 页面/输出页面的其余部分。

4

2 回答 2

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>  
于 2012-10-10T16:08:46.737 回答
0

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

摆脱

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

您没有正确使用 ID

$_POST["fname"];

而不是:$_POST["firstname"];

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

echo "test test ".$fname.$sname.$email.$phone."test test"; 
于 2012-10-10T16:09:25.400 回答