我正在尝试使用php连接到本地数据库。
我尝试检查所有内容,它们似乎都正确,但仍然失败
这是配置设置
<?php
$servername = "localhost";
$db_user ="root";
$db_pass = "";
$db_name = "useraccounts";
$db = new PDO("mysql:host= $servername; db_name= $db_name" , $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
这是我要发布的数据
<?php
if(isset($_POST['submit'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$referrer = $_POST['referrer'];
$nationality = $_POST['nationality'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "INSERT INTO users (firstname, lastname, referrer, nationality, phone, email, passowrd) VALUES(?,?,?,?,?,?,?)";
$stmtinsert = $db->prepare( $sql );
$result = $stmtinsert->execute([$firstname, $lastname, $referrer, $nationality, $phone, $email, $password]);
if($result) {
echo 'successfully saved.';
} else {
echo 'There was a problem';}
}
?>
我想发布到数据库,但是出现错误