没有使用php,mysqli提交到数据库

时间:2014-03-11 16:38:05

标签: php html database mysqli prepared-statement

我无法弄清楚为什么在通过验证并且没有提交到数据库之后它会破裂。刚出现空白屏幕。我已经回应了new_password并正在加密它。我错过了什么吗?或做错了什么?任何帮助/建议表示赞赏。提前谢谢。

if (isset($_POST['register'])){
    //Validation and post variable stuff here but doesn't appear to be any issue with it as I have tested it alot.
}
else if(!$error_msg && !$returned_record && $_POST['register']){
    function generateHash($password_1){
        if(defined("CRYPT_BLOWFISH") && CRYPT_BLOWFISH){
    //echo "WE HAVE CRYPT BLOWFISH";
    $salt = '$2y$11$'. substr(md5(uniqid(rand(), true)), 0, 22);
    return crypt($password_1, $salt);
     }//End If
}//End Function generateHash();

    $new_password = generateHash($password_1);
    //Build our query
$sql = ("INSERT INTO members (username, email, first_name, last_name, country, password_1) VALUES (?,?,?,?,?,?)");
//Prepare our query
$stmt = $mysqli->prepare($sql) or die("PREPARE DIDNT WORK");;
//Bind the fields and there parameters to our query
$stmt->bind_param('ssssss', $username, $email, $first_name, $last_name, $country, $new_password);
//Execute the query
$stmt->execute();
header('Location: http://someurl.com');
exit();
}

2 个答案:

答案 0 :(得分:0)

不是绑定参数,而是试试这个:

$sql = ("INSERT INTO members (username, email, first_name, last_name, country, password_1) VALUES (:username, :email, $first_name, :last_name, :country, :password_1)");

$stmt = $mysqli->prepare($sql) or die("Failed Execution");;

$stmt->execute(array(
 ':username' => $username,
 ':email'   => $email,
 ':first_name' => $fname,
 ':last_name' => $lname,
 ':country' $country,
 ':password_1' $password
));

答案 1 :(得分:0)

我想我已经想通了。我试图将这个代码实现到带有自定义循环的wordpress模板页面。我删除了所有循环/函数,它首先尝试。所以那里的东西引起了问题。谢谢你的尝试!