title: PHP use mySQL to check existing username
body: <p>I have been following this tutorial for building a simple registration / login script.</p>
  
  <p><a href="http://forum.codecall.net/topic/69771-creating-a-simple-yet-secured-loginregistration-with-php5/" rel="nofollow">http://forum.codecall.net/topic/69771-creating-a-simple-yet-secured-loginregistration-with-php5/</a></p>
  
  <p>I am new with PHP, but I have a lot of experience using C++, so I thought the transitions wouldn't be too hard, I just need to figure out the syntax. I also did a very very quick introduction to mySQL at university, so I thought it would be a lot easier to use mySQL to check for an existing username when the user has registered, though my knowledge isn't too good. I thought something like this would work;</p>
  
  <pre><code>SELECT username
  FROM codecalltut
  WHERE username = username;
  </code></pre>
  
  <p>Would this actually work? It is selecting the username from the database codecalltut and then it checks to see if the username being inputted is already a username? Even if this is correct I don't know how to include it in my PHP.</p>
  
  <p>I've tried using </p>
  
  <pre><code>$qry = "SELECT username
      FROM codecalltut
      WHERE username = username;"
  </code></pre>
  
  <p>But I just get a syntax error when it moves to the next statement.</p>
  
  <pre><code>&lt;?php 
      $qry = "SELECT username
          FROM codecalltut
          WHERE username = username;"
  
  //if register button was clicked.
  } else {
  $usr = new Users; //create new instance of the class Users
  $usr-&gt;storeFormValues( $_POST ); //store form values
  
  //if the entered password is match with the confirm password then register him
  if( $_POST['password'] == $_POST['conpassword'] ) {
  echo $usr-&gt;register($_POST); 
  } else {
  //if not then say that he must enter the same password to the confirm box.
  echo "Password and Confirm password not match"; 
  }
  }
  
  ?&gt;
  </code></pre>
  
  <p>This is the query used to construct the database:</p>
  
  <pre><code>CREATE DATABASE `codecalltut` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
  USE `codecalltut`;
  
  
  CREATE TABLE IF NOT EXISTS `users` (
    `userID` int(11) NOT NULL AUTO_INCREMENT,
    `username` varchar(50) NOT NULL,
    `password` varbinary(250) NOT NULL,
    PRIMARY KEY (`userID`,`username`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
  </code></pre>
  
  <p>This is the HTML code for when the user clicks "Register"</p>
  
  <pre><code>&lt;li class="buttons"&gt;
                           &lt;input type="submit" name="register" value="Register" /&gt;
                              &lt;input type="button" name="cancel" value="Cancel" onclick="location.href='index.php'" /&gt;
                       &lt;/li&gt;
  </code></pre>