Jump to content

Php Authentication Code: Username In User


rawkinyeti

Recommended Posts

Im trying to make it so a username cant be used twice in an application. The database will not accept the duplicate because username is the primary key, but i want to stop the user from advancing if the try and use the same username. So far what i have does not do this. Any suggestions?

$stmt3 = $conn->prepare("SELECT username FROM users WHERE username = ?");$stmt3->bind_param("s",$username);$stmt3->execute();$stmt3->store_result();$num_rows = $stmt3->num_rows;$stmt3->bind_result($result);    if($result['username'] == $username){  echo "Username has been already used. Please go back and try again.";	   }  Else  {    $stmt = $conn->prepare("Insert into users (username, password ) values (?,?)");   $stmt->bind_param("ss", $username, $password);   $stmt->execute();   $stmt1 = $conn->prepare("Insert into personal_info(last_name, first_name, student_id, address, city, state, zip, phone_number, email, country) values(?,?,?,?,?,?,?,?,?,?)");   $stmt1->bind_param("ssssssssss", $last_name, $first_name, $student_id, $address, $city, $state, $zip, $phone, $email, $country);   $stmt1->execute();   $stmt1->close();     /*** if all is done, say thanks ***/   header("Location: /Test/thankyou2/");

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...