im trying to get make the registration form check if user already exisits then give error else make the the account but somehow nto working (im little bit newbie to prepared statements) help me please thanks. And please don't downvote , i know there are already answer for this , i read them but not helped me.
<?php
// Include database connection and functions here.
include 'db_connect.php';
include 'functions.php';
// The hashed password from the form
$password = $_POST['p'];
// Create a random salt
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
// Create salted password (Careful with the chilli)
$password = hash('sha512', $password.$random_salt);
$username = $mysqli->real_escape_string($_POST['username']);
$email = $mysqli->real_escape_string($_POST['email']);
$stmt = $mysqli->prepare("SELECT * FROM members WHERE username = ? LIMIT 1");
$stmt->bind_param('s', $username);
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
if($stmt->num_rows == 1) {
header("Location: '..\..\..\?registrationfailed=1'");
}
else
{
if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt) VALUES (?, ?, ?, ?)"))
{
$insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
// Execute the prepared query.
$insert_stmt->execute();
header("Location: '..\..\..\?success=1'");
}
else
{
header("Location: '..\..\..\?registrationfailed=1'");
}
}
?>