I am trying to insert data into database using mysqli prepare statement on a localhost. Just started learning PHP after Java. Everything seems to be ok, since there are no errors being displayed.when I run it. I am using PHP version 7.4.11. It just will not insert data into database. I've been dealing with this for past 6 hours. I just can't get what's wrong with it. Here is the script
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('scream.enabled', false);
include_once 'dbCon.php';
$first = mysqli_real_escape_string($conn, $_POST['first']);
$last = mysqli_real_escape_string($conn, $_POST['last']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$sql = "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES (?, ?, ?, ?, ?);";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql))
{
echo "SQL ERROR!";
}
else
{
mysqli_stmt_bind_param($stmt, "sssss", $first, $last, $email, $uid, $pwd);
mysqli_stmt_execute($stmt);
}
I have also tried with backticks and diferrent approach:
$stmt = mysqli_prepare($conn, "INSERT INTO `users` (user_first, user_last, user_email,user_uid, user_pwd) VALUES (?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, $first, $last, $email, $user_uid, $pwd);
if(mysqli_stmt_execute($stmt)){
echo "Data finally inserted.";
}
else{
echo "ERROR ofcourse";
}
I also tried a number of other approaches which I've found in answered questions, but it just will not work. Please help. Thank you.