This works...kinda

This works...kinda

I am using jquery for a user registration form that sends the the info to a PHP 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.
  1. if (isset($_POST['name'])) {
  2. #Check to see if requested name already exists
  3. $name $_POST['name'];
    $siteid $_POST['siteid'];
    $checkname mysql_query("SELECT * FROM projects WHERE url = '$name'");
    $founduser mysql_num_rows($checkname);

    if (

    $founduser == 0) {
    mysql_query("UPDATE projects SET url = '$name' WHERE siteid = $siteid"); exit("URL updated successfully");}
  4. if ($founduser != 0) {
    echo
    "$name already exists in the database.  Please select another name";}
  5. }

If I remove the UPDATE statement and simply return an echo statement for each IF statement, everything works fine:
  1. if ($founduser == 0) {
    echo
    "$name is available";}

  2. if ($founduser != 0) {
    echo
    "$name already exists in the database.  Please select another name";}
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. 

I have tried every possible solution I can think of to make the script work but have had no luck.  I have spent enough time working through the PHP code and have to assume there is something weird going on since I am using jquery to send the data to the script.

Any ideas?