非常感謝大家。 HTML是好的,我相信JavaScript仍然是一個問題,和PHP看起來不錯,但我需要更多的指針。我已經編輯我的代碼如下...請評論/評論:php mysql javascript(not school)
HTML:
<input name="uname" type="text" placeholder="please enter a user name" required><br />
<input name="upassword" type="text" placeholder="please enter a password or passphrase" required><br />
<input id="register" name="register" type="submit" class="btn btn-primary btn-lg outline" onclick="register();"/>
功能寄存器(){
的JavaScript
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "register.php",
data: { name: "uname", password: "password"},
success: function (result) {
alert("success");
}
});
}
而我的最大的問題,PHP
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
define('USER', 'root');
define('PASS', 'Schwinny2156!');
try {
$conn = new PDO("mysql:host=localhost;dbname=users;", USER, PASS);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('INSERT INTO `users` (name, password VALUES (:name,:password)');
$stmt->bindParam(':name', $_POST['uname']);
$stmt->bindParam(':password', $_POST['upassword']);
$stmt->execute()
}
catch(PDOException $e)
{
echo $stmt . "<br>" . $e->getMessage();
}
$stmt = null;
首先這有沒有關係引導和第二,如果我看到這是正確的,你不與你的PARAMS。看到這個鏈接的例子:http://php.net/manual/de/mysqli.quickstart.prepared-statements.php – JRsz
缺少從'define('name',$ _POST ['uname'];' – RamRaider
password_hash和password_verify,執行[Right Way](http://stackoverflow.com/a/32556010) – Drew