无法获取html表单与PHP一起使用

时间:2015-01-23 22:04:18

标签: php html forms

我不能为我的生活得到这种简单的形式......

怎么了?

    <form action="" method="post">
    <input type="text" name="kupongkode" placeholder=" Kupongkode?"> <input
        type="submit" value="&#x2713;" id="kupongkodeKnapp">
</form>

<?php
if (isset ( $_POST ['kupongkodeKnapp'] )) {
    if ($_POST ['kupongkode'] == "TEST")
        echo "Godkjent!";

    else
        echo "Ikke godkjent";
}

?>

5 个答案:

答案 0 :(得分:2)

您提交的名称属性缺失

    <form action="index.php" method="post">
        <input type="text" name="kupongkode" placeholder=" Kupongkode?">
        <input type="submit" value="&#x2713;" name="kupongkodeKnapp" id="kupongkodeKnapp">
    </form>

    <?php
    if (isset ( $_POST ['kupongkodeKnapp'] )) {
        if ($_POST ['kupongkode'] == "TEST")
            echo "Godkjent!";
        else
            echo "Ikke godkjent";
    }
    ?>

答案 1 :(得分:1)

在表单提交上,您总是希望通过&#34; name&#34;来引用表单元素。属性&#34 ;.这是前端(JavaScript)和后端(PHP或其他)的情况。

<?php
if (isset ( $_POST ['kupongkode'] )) {
if ($_POST ['kupongkode'] == "TEST")
    echo "Godkjent!";
else
    echo "Ikke godkjent";
}

答案 2 :(得分:0)

使用isset

检查时,提交按钮的名称必须相同

您应该通过this链接。

答案 3 :(得分:0)

你犯了一个错误,你应该使用name代替id

<form action="" method="post">
    <input type="text" name="kupongkode" placeholder=" Kupongkode?"> <input
        type="submit" value="&#x2713;" name="kupongkodeKnapp">
</form>

<?php
if (isset ( $_POST ['kupongkodeKnapp'] )) {
    if ($_POST ['kupongkode'] == "TEST")
        echo "Godkjent!";

    else
        echo "Ikke godkjent";
}

?>

答案 4 :(得分:0)

试试这样:

<form action="" method="post">
<input type="text" name="kupongkode" placeholder=" Kupongkode?"> 
<input type="submit" value="&#x2713;" id="kupongkodeKnapp">
 </form>
 <?php
 if (isset($_POST)){
if ($_POST ['kupongkode'] == "TEST")
    echo "Godkjent!";

else
    echo "Ikke godkjent";
}

?>