PHP表单不存储和输出数据

时间:2018-01-07 07:28:21

标签: php html forms

我是PHP的新手,需要创建一个表单。当我按submit时,我的表单不输出我输入到表单中的数据。这些文件是从我的Apache服务器的htdocs文件夹运行的。任何帮助将不胜感激。

这是我的HTML代码

 <html>
<body>

    <style>
      body {
        background-color: #66c2ff;
        font-family: 'Tangerine', serif;
        font-size: 24px;
      }
    </style>

        <div id="header" class="section">
            <p style="text-align:center;"> <img src="http://i63.tinypic.com/34sgvpy.png"> </p>
            <p align="center">Welcome</p>
        </div>


<form action="abiform.php" method="post">
<p>Company Name: <input type="text" name="yourname" /><br />
<br />
E-mail: <input type="text" name="email" /><br /></P>

<p>Urgency:
<input type="radio" name="urgency" value="Low" checked="checked" /> Low
<input type="radio" name="urgency" value="Medium" /> Medium
<input type="radio" name="urgency" value="High" /> High</p>

<p>Existing Feature or Issue:
<input type="radio" name="existingissue" value="Yes" checked="checked" /> Yes
<input type="radio" name="existingissue" value="No" /> No
<input type="radio" name="existingissue" value="Not Sure" /> Not Sure</p>

<p>Max Hours Willing to Spend on Issue: <input type="text" name="hours" /><br /></P>

<p>Issue Description:<br />
<textarea name="description" rows="10" cols="40"></textarea></p>

<p>Expected Outcome:<br />
<textarea name="outcome" rows="10" cols="40"></textarea></p>

<p><input type="submit" value="Submit"></p>
</form>

</body>
</html>

我的PHP表格

<?php
$yourname = check_input($_POST['yourname']);
$email = check_input($_POST['email']);
$urgency = check_input($_POST['urgency']);
$existingissue = check_input($_POST['existingissue']);
$hours = check_input($_POST['hours']);
$description = check_input($_POST['description']);
$outcome = check_input($_POST['outcome']);
?>

<html>
<body>

Company Name: <?php echo $_POST['yourname']; ?><br />
<br />
Company e-mail: <?php echo $_POST['email']; ?><br />
<br />
Urgency: <?php echo $_POST['urgency']; ?><br />
<br />
Existing Feature or Issue? <?php echo $_POST['existingissue']; ?><br />
<br />
Max Hours Willing to Spend on Issue: <?php echo $_POST['hours']; ?><br />
<br />
Issue Description:<br />
<?php echo $_POST['description']; ?>
<br />
Expected Outcome:<br />
<?php echo $_POST['outcome']; ?>

</body>
</html>

<?php
function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>

2 个答案:

答案 0 :(得分:0)

因为你试图在创建之前检查输入,像这样编辑你的php文件。

<?php

function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

$yourname = check_input($_POST['yourname']);
$email = check_input($_POST['email']);
$urgency = check_input($_POST['urgency']);
$existingissue = check_input($_POST['existingissue']);
$hours = check_input($_POST['hours']);
$description = check_input($_POST['description']);
$outcome = check_input($_POST['outcome']);
?>

<html>
<body>

Company Name: <?php echo $_POST['yourname']; ?><br />
<br />
Company e-mail: <?php echo $_POST['email']; ?><br />
<br />
Urgency: <?php echo $_POST['urgency']; ?><br />
<br />
Existing Feature or Issue? <?php echo $_POST['existingissue']; ?><br />
<br />
Max Hours Willing to Spend on Issue: <?php echo $_POST['hours']; ?><br />
<br />
Issue Description:<br />
<?php echo $_POST['description']; ?>
<br />
Expected Outcome:<br />
<?php echo $_POST['outcome']; ?>

</body>
</html>

答案 1 :(得分:0)

问题出在localhost上。解决方案是在这个帖子中:PHP code is not being executed, instead code shows on the page。这是https问题,我必须使用HTML localhost打开https文件