quiksilver02x Posted November 12, 2010 Share Posted November 12, 2010 I have a script to check for duplicate username's on signup. Even when there is no entry found and the script preforms the update statement, the error will come back indicating the requested name already exists. #Check to see if requested name already exists $name = $_POST['name']; $siteid = $_POST['siteid']; $checkname = mysql_query("SELECT * FROM projects WHERE url = '$name'"); $founduser = mysql_num_rows($checkname); if ($founduser != 0) { echo"$name already exists in the database. Please select another name";} if ($founduser == 0) { mysql_query("UPDATE projects SET url = '$name' WHERE siteid = $siteid"); die; echo"URL updated successfully";} If I remove the UPDATE statement and simply return an echo statement for each IF statement, everything works fine: if ($founduser != 0) { echo"$name already exists in the database. Please select another name";} if ($founduser == 0) { echo"$name is available";} So what's happening is, when $founduser == 0, the update script preforms just fine and the database is populated correctly, but then the entire script will then re-run itself and find the name that was just entered, resulting in $founduser != 0. How do I stop the script when it preforms the UPDATE statement? I tried putting die; in after the UPDATE statement, but the entire script still re-runs itself. I am pulling my hair out here... Quote Link to comment Share on other sites More sharing options...
dheeraja Posted November 12, 2010 Share Posted November 12, 2010 Just put your script under the below code: if(isset($_POST['name'])) { //Your Code } Quote Link to comment Share on other sites More sharing options...
quiksilver02x Posted November 24, 2010 Author Share Posted November 24, 2010 When I saw your response I thought...Oh yeah!! I figured it was the solution, but I am still having the same problem. I'm using jQuery to send the data to my PHP script...could there be something weird going on there? I have tried everything possible to make the script work but have had no luck. Quote Link to comment 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.