尝试使用PHP创建注册表单

时间:2015-03-29 21:43:27

标签: php html mysql pdo

我正在尝试为我正在开发的Web应用程序创建一个SignUp表单,并且在一段时间内没有使用mySQL进行编程,当我填写HTML表单时,我只是进入一个空白页面(register.php)而没有值被传递到数据库表中。代码,包括HTML和PHP,如下所示。对于我所遗漏的内容或为何不通过的任何指导都将深表感谢。

这是要注册的HTML表单:

        <div class="panel-body">
        Please fill out the form below.
        <br>
        <form action="register.php" method="post">
        <div class="form-group">
        <label for="exampleInputEmail1">Email address</label>
        <input type="email" class="form-control" id="exampleInputEmail1" name="email" placeholder="Enter email">
        </div>
        <div class="form-group">
        <label for="exampleInputPassword1">Password</label>
        <input type="password" class="form-control" id="exampleInputPassword1" name="password" placeholder="Password">
        </div>
        <button type="submit" class="btn btn-default">Sign Up</button>
        </form>

以下是register.php上的代码:

$user = "smartkrawldb";
$pass = "Nixon15!";
$db = new PDO( 'mysql:host=XX.XXX.XXX.XX,dbname=smartkrawldb, $user, $pass);

$form = $_POST;
$email = $form['email'];
$password = $form['password'];

$sql = "INSERT INTO users ( email, password) VALUES ( :email, :password)";
$query = $db->prepare( $sql );
$query->execute( array(':email'=>$email, ':password'=>$password));   

2 个答案:

答案 0 :(得分:1)

如果您尝试这样做会有效吗?

$email = $_POST['email'];
$pass = $_POST['pass'];
$query = mysql_query("SELECT * FROM users WHERE email = '{$email}' AND password = '{$pass}';

我强烈建议您切换到PHP的PDO Object工作流程,这样更安全,更易于使用。

答案 1 :(得分:0)

$ _ POST ['submit']根本没有传递任何值(它是提交按钮)。

尝试var_dump,将最后一行更改为:

if(isset($_POST['submit'])) { 
signUp(); 
}
else {
     echo "the problem with post_submit is that is not here inside: ";
     var_dump($_POST);
     }

了解$ _POST超全局内部的内容。

喝彩!