当我想为我的数据库提交数据时,我遇到了失败。连接已建立,但是当我使用时:
$sql = $MyConnection->prepare("
INSERT INTO AMP_USERS (Username, Password, Lastname, Email) VALUES ('$username', '$password', '$lastname', '$email')
");
$sql->execute();
我失败了。我已经完成了:
$sql->bindParam(:username, $username)
依此类推,但这不起作用/没有提供错误。不知何故,数据没有存储到数据库中,错误一定在这段代码的某个地方。
编辑
虽然我不认为所有的代码都是必要的,但我会发布它:
<?php
require('config.php');
if($MyConnection = new PDO('mysql:host=fdb6.biz.nf;dbname=1446018_venator', $dbusername, $dbpassword)) {
echo "A connection has been made!";
}
$username = $_POST['username'];
$password = $_POST['password'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
// Hasing the password:
// A higher "cost" is more secure but consumes more processing power
$cost = 10;
// Create a random salt
$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
// Prefix information about the hash so PHP knows how to verify it later.
// "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
$salt = sprintf("$2a$%02d$", $cost) . $salt;
// Hash the password with the salt
$hash = crypt($password, $salt);
$sql = $MyConnection->prepare("
INSERT INTO AMP_USERS (Username, Password, Lastname, Email) VALUES (:username, :password, :lastname, :email)
");
$sql->bindParam(':username', $username);
$sql->bindParam(':password', $hash);
$sql->bindParam(':lastname', $lastname);
$sql->bindParam(':email', $email);
$sql->execute();
?>