title: Check if username exists by php - and keep values
body: <p>I'm trying to write a registration form, and when the user press the "submit" button, I want to check if the username already exists - and if so, to show a pop-up window that says "user name already exists - please change it".
  when the user closes that pop-up window using Javascript - I want the rest of the fields that the user inserts to stay in their place (I mean, only the username will be deleted - but the first name for example, will stay)</p>
  
  <p>here's the code I wrote:</p>
  
  <pre><code>$con=mysqli_connect("localhost","root","","shnitzale");
          // Check connection
          if (mysqli_connect_errno())
            {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
            }
  
           $check="SELECT count (username) as num FROM registered_clients WHERE username=$_GET[User]";
           if (!mysqli_query($con, $check))
           {
               echo "Username already exist";
           }
           else
           {
               $sql="INSERT INTO registered_clients (Username, Password, First_name, Last_name,
                  Day, Month, Year, Gender, Address, City, Phone_Number1, Phone_number2, Email)
                  VALUES
                  ('$_GET[User]','$_GET[Password]','$_GET[Fname]','$_GET[Lname]','$_GET[Day]',"
                       . "'$_GET[Month]','$_GET[Year]','$_GET[gender]','$_GET[Address]','$_GET[City]',"
                       . "'$_GET[Phone1]','$_GET[Phone2]','$_GET[Email]')";
  
               if (!mysqli_query($con,$sql))
               {
                 die('Error: ' . mysqli_error($con));
               }
  
               echo "Thank you $_GET[Fname] $_GET[Lname]";
           }
              mysqli_close($con);
  </code></pre>
  
  <p>all of this is in a seperate php file that I go to after I press the "submit" button,
  I understand that I need to check the username validation before I get to this page, but I don't really know how...
  Thank you!</p>