title: PHP, Checking if an Email is already in database
body: <p>I am having troubles with my php code. What I have going on here is a form that gets sent to this file and enters it into a database. It does NOT enter into the database if the email is already in the database in an account. What I am having troubles with is I want to print out "And account with that email is already created" when that email is already in the database and print out "Account created" when it inserts the email into the database. What is wrong with it is no matter what email I enter when creating a new account, it runs the if statement even if I enter an email that is new the database. Just to be clear, the database will enter the email if it is a new email however my code will just automatically use the if statement.</p>
  
  <p>Here is my code in php:</p>
  
  <pre><code>$fName=$_POST['fName'];
  $lName=$_POST['lName'];
  $email=$_POST['email'];
  $password=$_POST['password'];
  $state=$_POST['state'];
  $zip=$_POST['zip'];
  $address1=$_POST['address1'];
  
  Print"&lt;h3&gt;";
  Print"&lt;a href ='projectHome.php'&gt;Store Home&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;";
  Print"&lt;a href ='createAccount.php'&gt;Create an Account&amp;nbsp;&amp;nbsp;&amp;nbsp;   &lt;/a&gt;";
  Print"&lt;a href ='login.php'&gt;Login&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;";
  Print"&lt;a href='BrowseCategories.php'&gt;Browse Categories&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/a&gt;";
  Print"&lt;a href='search.php'&gt;Search for a book&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/a&gt;";
  Print"&lt;a href='orders.php'&gt;Orders&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/a&gt;";
  Print"&lt;a href ='contactUs.php'&gt;Contact Us&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;";
  Print"&lt;a href ='index.html'&gt;Home(index)&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;";
  Print"&lt;/h3&gt;";
  
  
  $query="insert into Customers(Email,Passwd,FirstName,LastName,Address1,ZipCode,State) VALUES ('$email','$password','$fName','$lName','$address1',$zip,'$state')";
  mysql_query($query);
  
  $query="select * from Customers where Email = '$email'";
  $result=mysql_query($query);
  $numOfRows=mysql_numrows($result);
  if($numOfRows==1)
  {
      print"An account with that email is already created..&lt;a href ='createAccount.php'&gt;Please enter a new account email.&lt;/a&gt;";
      print"&lt;a href ='createAccount.php'&gt;&lt;/a&gt;";
  
  }
  else
  {
      print"Account created.";
  }
  
  
  @mysql_close($connection);
  </code></pre>
  
  <p>Thank you!</p>