准备好的声明没有执行

时间:2017-06-20 21:02:55

标签: php mysqli

我使用预准备语句注册的php脚本无效,我无法弄清楚原因 有人可以查看我的代码吗?谢谢你,如果这个帖子重复,我很抱歉这个帖子,但我自己无法想象

代码:

<?php

require_once 'connect.php';

$email = $_POST['email'];
$password = $_POST['password'];
$passwordR =  $_POST['confpassword'];

if ($password == $passwordR) {

$password = hash('sha512', $password); // použi password_hash
$prep_stmt = "SELECT * FROM users WHERE email= ? ";
$stmt = connect()->prepare($prep_stmt);

if ($stmt) {
    $stmt->bind_param('s', $email);
    $stmt->execute();
    $stmt->store_result();

    if ($stmt->num_rows == 1) {
        echo 0;
        die();

    } else {

        if ($insert_stmt = connect()->prepare("INSERT INTO users (email, password) VALUES ( ?  ,  ? )")) {
            $insert_stmt->bind_param('ss', $email, $password);
            $insert_stmt->execute();
            if (!$insert_stmt) {
                echo 2;
                echo mysqli_stmt_sqlstate($insert_stmt);
                die();
            } else {
                echo 1; //preslo to
                die();
            }
        }
    }
} else {
    echo 3; //db error
    die();
}
}

0 个答案:

没有答案