I'm running into a problem trying to insert data into mysql table. My connection to the database seems fine, however all that gets returned is my "Connected Successfully" message - not "Sign up Complete!" My table name is 'user' and I've double checked the value names are correct, so I don't know what it is. Here is my process.php code:
if (empty($_POST["firstname"])) {
die("First name required!");
}
if(empty($_POST["surname"])) {
die("Surname required!");
}
if (! filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
die("Please enter a valid email!");
}
if (strlen($_POST["password"]) < 8) {
die("Password must be atleast 8 characters long!");
}
if ( ! preg_match("/[0-9]/", $_POST["password"])) {
die("Password must contain at least one number!");
}
if ($_POST['password'] !== $_POST['passwordconfirm']) {
die("Passwords must match!");
}
$password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT);
$conn = require __DIR__ . "/database.php";
$sql = "INSERT INTO user (firstname, surname, email, password_hash) VALUES (?, ?, ?, ?)";
$stmt = $conn->stmt_init();
$stmt->bind_param("sss",
$_POST["firstname"],
$_POST["surname"],
$_POST["email"],
$password_hash);
$stmt->execute();
echo "Signup complete!";
here is my database connection class:
<?php
$host = "localhost";
$dbname = "login_db";
$username = "root";
$password = "";
$conn = new mysqli( $host,
$username,
$password,
$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>