rawkinyeti Posted October 13, 2011 Share Posted October 13, 2011 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 More sharing options...
justsomeguy Posted October 13, 2011 Share Posted October 13, 2011 Check the $num_rows variable instead to see if any rows were returned. Link to comment Share on other sites More sharing options...
rawkinyeti Posted October 18, 2011 Author Share Posted October 18, 2011 Did the trick. changed $result to $num_rows and had it see if it was one or zero. Thank for the insight. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.