title: checking record before inserting in sql using php
body: <p>i am adding records using INSERT statement. now i want to check whether the email has already been registered or already present in the records..if it is already present just give an error otherwise insert a new record.. this is how iam doing it... but the select query is not running...and still adding records without checking.please check my code and please suggest a solution. Thanks :) here is my code for </p>
  
  <pre><code> manage-users.php
  &lt;?php include("../includes/config.php"); ?&gt;
  &lt;?php
  if ($_SESSION["isadmin"])
  {
  ?&gt;
  &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;?php include("includes/pre-header.php");?&gt;
  
  
  &lt;title&gt;Admdin Home&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="container"&gt;
  &lt;?php include("includes/header.php"); ?&gt;
  &lt;?php include("includes/nav.php"); ?&gt;
  &lt;div id="maincontent"&gt;
  
  &lt;div class="span-24 last"&gt;
  &lt;div id="breadcrumbs"&gt;
      &lt;a href=""&gt;Home&lt;/a&gt; &gt;
      &lt;a href=""&gt;Manage Users&lt;/a&gt; &gt;
      Add New
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;?php include("includes/manage-users-aside.php"); ?&gt;
  &lt;div class="span-18 last"&gt;
  &lt;h2 class="alt"&gt;Add New&lt;/h2&gt;
  &lt;?php
  if (isset($_GET["status"]))
  {
  if($_GET["status"]==1)
  {
  ?&gt;
  &lt;div class="success"&gt;
  &lt;?php
  echo("&lt;strong&gt;User Has Been Added Successfully!&lt;/strong&gt;");
  ?&gt;
  &lt;/div&gt;
  &lt;?php
  }
   if($_GET["status"]==2)
  {
  ?&gt;
  &lt;div class="success"&gt;
  &lt;?php
   echo("&lt;strong&gt;User Has Been Edited Successfully!&lt;/strong&gt;");
  ?&gt;
  &lt;/div&gt;
  &lt;?php
  }
  } 
   if($_GET["status"]==3)
  {
  echo ("&lt;strong&gt;This Account Already Exixts!. Please add a New One!&lt;/strong&gt;");
  }
  ?&gt;
  &lt;form method="post" id="form" action="manage-users-action.php"&gt;
  &lt;label for="email"&gt;Email/Username:&lt;/label&gt;&lt;input id="email" type="text" name="email" value="" class="text" /&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;label for="password"&gt;Password:&lt;/label&gt;&lt;input id="password" type="password" name="password"  value="" class="text" /&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;label for="firstname"&gt;First Name:&lt;/label&gt;&lt;input id="firstname" type="text" name="firstname" value="" class="text" /&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;label for="lastname"&gt;Last Name:&lt;/label&gt;&lt;input id="lastname" type="text" name="lastname"    value="" class="text" /&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;label&gt;Type:&lt;/label&gt;&lt;br /&gt;
  &lt;input type="radio" name="type" value="S" /&gt;Student &lt;br /&gt; &lt;br /&gt;
  &lt;input type="radio" name="type" value="T" /&gt;Teacher&lt;br /&gt;&lt;br /&gt;
  &lt;input type="submit" name="submit"  value="Submit" class="button" /&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;?php include("includes/footer.php"); ?&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  &lt;?php
  }
  else
  {
      header("Location: ".$fullpath."login/unauthorized.php");
  
   }
  ?&gt;
  </code></pre>
  
  <p>this is      manage-users-action.php</p>
  
  <pre><code>&lt;?php include("../includes/config.php");?&gt;
  &lt;?php
  $fname=$_POST['firstname'];
  $lname=$_POST['lastname'];
  $type=$_POST['type'];
  $email=$_POST['email'];
  $pwd=$_POST['password'];
  $recoverykey=md5(time());
  $encpwd=md5($pwd);
  $con=mysql_connect($dbserver,$dbusername,$dbpassword);
  if (!$con) { die('Could not connect: ' . mysql_error()); }
  mysql_select_db($dbname, $con);
  
  $result= mysql_query("SELECT FROM accounts WHERE (email='".$email."')");
  if(!$result){
  $sql=("INSERT INTO accounts VALUES   (NULL,'".$email."','".$encpwd."','".$fname."','".$lname."','".$type."','".$recoverykey."')"    );
  }
  else
  {
   header("Location: manage-uesrs.php?status=3");
  }
  if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
  else
      {
          header("Location:manage-users.php?status=1");
      }
  
  mysql_close($con);
  ?&gt;
  </code></pre>