title: Adding a 'check username' to registration form PHP
body: <p>Please could someone give me some much needed direction...</p>
  
  <p>I have a registration form, however I need to add a condition that if the username is already in the table, then a message will appear. I have a had a few goes except it just keeps adding to the SQL table.</p>
  
  <p>Any help would be much appreciated. Here is my current code:</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>    &lt;?php
      session_start();session_destroy();
      session_start();
      $regname = $_GET['regname'];
      $passord = $_GET['password'];
      if($_GET["regname"] &amp;&amp; $_GET["regemail"] &amp;&amp; $_GET["regpass1"] &amp;&amp; $_GET["regpass2"] )
      {
          if($_GET["regpass1"]==$_GET["regpass2"])
  {
      $host="localhost";
      $username="xxx";
      $password="xxx";
      $conn=  mysql_connect($host,$username,$password)or die(mysql_error());
      mysql_select_db("xxx",$conn);
      $sql="insert into users (name,email,password) values('$_GET[regname]','$_GET[regemail]','$_GET[regpass1]')";
      $result=mysql_query($sql,$conn) or die(mysql_error());
      print "&lt;h1&gt;you have registered sucessfully&lt;/h1&gt;";
  
      print "&lt;a href='login_index.php'&gt;go to login page&lt;/a&gt;";
  }
      else print "passwords don't match";
      }
      else print"invaild input data";
  
      ?&gt;
  </code></pre>