mysql - PHP code for registering a user is not working -


i code registering user. code works, , adds new user. seems ignore part has check if there user registered username or email.

<?php // include database connection , functions here. include 'db_connect.php'; include 'functions.php'; // hashed password form $password = $_post['p']; // create random salt $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true)); // create salted password (careful chilli) $password = hash('sha512', $password.$random_salt); $username = $_post['username']; $email = $_post['email'];  $result = mysqli_query($con,"select * members username='$username'"); $username_check = mysqli_fetch_array($result);  $result_email = mysqli_query($con,"select * members email='$email'"); $email_check = mysqli_fetch_array($result_email);  if ($username == $username_check['username']){     mysqli_close();     header("..\..\..\?error12");     exit;     }else{  if($email == $email_check['email']){     mysqli_close();     header("..\..\..\?error13");     exit;     }else{  if ($insert_stmt = $mysqli->prepare("insert members (username, email, password, salt) values (?, ?, ?, ?)")){    $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);     // execute prepared query.     $insert_stmt->execute();     header("location: '..\..\..\?success=1'");     }else{     header("location: '..\..\..\?registrationfailed=1'"); }}}?> 

try this

$result = mysqli_query($con,"select * members username='$username'";  if(mysqli_num_rows($result) == 0){  //this means no match found in database proceed     $insert_stmt = $mysqli->prepare("insert members (username, email, password, salt) values (?, ?, ?, ?)")){    $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);     // execute prepared query.     $insert_stmt->execute();     header("location: '..\..\..\?success=1'");  }else{ //this username exists mysqli_close();     header("..\..\..\?error12");     exit; } 

the above used check user e-mail too


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -