jose Posted April 22, 2010 Share Posted April 22, 2010 Hi there, No matter what "username" and "password" type in my machine to test my code, the program replays: An account already exists for this username. that's the code: <?php require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect('localhost', 'root', 'zambullo', 'entrepreneurial groups') or die ('Error connecting to MySQL server'); if (isset($_POST['submit'])) { // Grab the profile data from the POST $username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $password = mysqli_real_escape_string($dbc, trim($_POST['password'])); $repeatpassword = mysqli_real_escape_string($dbc, trim($_POST['repeatpassword'])); if (!empty($username) && !empty($password) && !empty($repeatpassword) && ($password == $repeatpassword)) { // Make sure someone isn't already registered using this username $query = "SELECT * FROM Entrepreneurialgroups_user WHERE username = '$username'"; $result = mysqli_query($dbc, $query); if ($result = $mysqli->query) { // The username is unique, so insert the data into the database $query = "INSERT INTO entrepreneurialgroups _user (username, password) VALUES ('$username', '$password')"; $row_cnt = $result->num; // Confirm success with the user echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>'; mysqli_close($dbc); exit(); } else { // An account already exists for this username, so display an error message echo '<p class="error">An account already exists for this username.</p>'; $username = ""; } } else { echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>'; } } mysqli_close($dbc); ?> I appreciate your help Quote Link to comment https://forums.phpfreaks.com/topic/199404-an-account-already-exists-for-this-username/ Share on other sites More sharing options...
MadTechie Posted April 22, 2010 Share Posted April 22, 2010 Erm.. you may want to look at this line again! if ($result = $mysqli->query) { Quote Link to comment https://forums.phpfreaks.com/topic/199404-an-account-already-exists-for-this-username/#findComment-1046517 Share on other sites More sharing options...
Ken2k7 Posted April 22, 2010 Share Posted April 22, 2010 $query = "INSERT INTO entrepreneurialgroups _user (username, password) VALUES ('$username', '$password')"; What is that? You have 2 different tables? And is there a space or not? Also, you shouldn't trim passwords. What if someone decided to start a password with a space? Is that illegal? Now to the problem: if ($result = $mysqli->query) { What is $mysqli? That's not a defined variable/object. Quote Link to comment https://forums.phpfreaks.com/topic/199404-an-account-already-exists-for-this-username/#findComment-1046518 Share on other sites More sharing options...
MadTechie Posted April 22, 2010 Share Posted April 22, 2010 I'm going offline so i better say 1. You would need to be == instead of = 2. it will alway return false as $mysqli->query will produce an error 3. try counting the rows instead ie if ($result->num_rows == 0) { Quote Link to comment https://forums.phpfreaks.com/topic/199404-an-account-already-exists-for-this-username/#findComment-1046522 Share on other sites More sharing options...
jose Posted April 22, 2010 Author Share Posted April 22, 2010 if ($result = $mysqli->query) { was the problem. if ($result->num_rows == 0) { works! (for now) Thanks, guys! Quote Link to comment https://forums.phpfreaks.com/topic/199404-an-account-already-exists-for-this-username/#findComment-1046567 Share on other sites More sharing options...
MadTechie Posted April 22, 2010 Share Posted April 22, 2010 welcome, if this is solved please click topic solved Quote Link to comment https://forums.phpfreaks.com/topic/199404-an-account-already-exists-for-this-username/#findComment-1046569 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.