表单不向POST数组PHP提交值

时间:2013-05-24 21:09:45

标签: php html forms post

我的表格可以在下面看到:

<form id="myForm" action="register.php" method="POST">
    <input type="text" name="email" id="email" onfocus="fieldSwap('inputhover.png')" 
        onblur="fieldSwap('inputnorm.png')"><br/>
    <input type="image" src="submitnorm.png" name="submit" id="submit" 
        alt="submit button" onMouseOver="buttonSwap('submithover.png')" 
        onMouseOut="buttonSwap('submitnorm.png')" 
        onMouseDown="buttonSwap('submitclick.png')" 
        onMouseUp="buttonSwap('submitnorm.png')"/>
</form>

它调用此脚本:

<?php
    require_once 'db.php';

    $email = $_POST['email'];
    echo $email;
    echo "Register form";
    $sql->$db->prepare("INSERT INTO emails SET email = :email");
    $sql -> bindValue(':email', $email, PDO::PARAM_STR);
    $sql -> execute();

    // Redirect back to homepage
    header('Location: index.php');
    exit();
?>

我收到此错误:

注意:未定义的索引:第3行的C:\ wamp \ www \ Holding page \ register.php中的电子邮件

我做错了什么?我知道POST数组中不存在名为email的索引,但我不确定为什么会这样。 谢谢!

2 个答案:

答案 0 :(得分:2)

尝试通过

提交表单
<input type="submit" value="send">

并查看是否适用于`print_r()

可悲的是,我不知道为什么<input type="image">不适合你。尝试检查doctype(必须是HTML5)和浏览器(太旧了?)。

答案 1 :(得分:0)

您忘记在value中添加email属性以及如果输入type=image不适用于submit按钮,那么您可以尝试type=submit

<form id="myForm" action="register.php" method="POST">
<input type="text" name="email" id="email" value="" onfocus="fieldSwap('inputhover.png')" onblur="fieldSwap('inputnorm.png')"><br/>
<input type="submit" src="submitnorm.png" name="submit" id="submit" alt="submit button" onMouseOver="buttonSwap('submithover.png')" onMouseOut="buttonSwap('submitnorm.png')" onMouseDown="buttonSwap('submitclick.png')" onMouseUp="buttonSwap('submitnorm.png')"/>
</form>