title: How to validate email id and password & confirm password in php
body: <p>i doing register form in php. i dont know how to validate my entered email and (password and confirm password) in php. For email if i enter same id "It should tell my email alread registered" and for password and confirmpassword should check whether it same or not. I have tried email in my coding. it throwing error email already registed but i want to display error in login screen. Please help for this two things. i am very new to php. sorry for my poor english. 
  I have return my code below,</p>
  
  <pre><code>&lt;?php
  require('config.php');
  // If the values are posted, insert them into the database.
  if (isset($_POST['username']) &amp;&amp; isset($_POST['password'])){
      $username = $_POST['username'];
      $email = $_POST['email'];
      $password = $_POST['password'];
      $cpassword = $_POST['confirmpassword'];
      $slquery = "SELECT 1 FROM register WHERE email = '$email'";
      $selectresult = mysql_query($slquery);
      if(mysql_num_rows($selectresult)&gt;0)
      {
          die('email already exists');
      }
  
      $query = "INSERT INTO `register` (username, password,confirmpassword, email) VALUES ('$username', '$password', '$cpassword', '$email')";
      $result = mysql_query($query);
      if($result){
          $msg = "User Created Successfully.";
      }
     }
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Login screen&lt;/title&gt;
      &lt;style type="text/css"&gt;
      .register-form{
          width: 500px;
          margin: 0 auto;
          text-align: center;
          padding: 10px;
          padding: 10px;
          background : #c4c4c4;
          border-radius: 10px;
          -webkit-border-radius:10px;
          -moz-border-radius:10px;
      }
      .register-form form input{padding: 5px;}
      .register-form .btn{
          background: #726E6E;
          padding: 7px;
          border-radius: 5px;
          text-decoration: none;
          width: 50px;
          display: inline-block;
          color: #FFF;
      }
      .register-form .register{
          border: 0;
          width: 60px;
          padding: 8px;
      }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="register-form"&gt;
      &lt;?php
          if(isset($msg) &amp; !empty($msg)){
          echo $msg;
      }
      ?&gt;
      &lt;?php
      if(isset($errormes))
      {
          echo $errormes;
      }
      ?&gt;
          &lt;h1&gt;Register&lt;/h1&gt;
          &lt;form action="" method="POST"&gt;
              &lt;p&gt;&lt;label&gt;User Name: &lt;/label&gt;
              &lt;input type="text" id="username" name="username" placeholder="Username"&gt;
              &lt;/p&gt;
              &lt;p&gt;&lt;label&gt;E-Mail&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :&lt;/label&gt;
              &lt;input id="email" name="email" type="email"&gt;
              &lt;/p&gt;
              &lt;p&gt;&lt;label&gt;Password&amp;nbsp;&amp;nbsp; :&lt;/label&gt;
              &lt;input id="password" name="password" type="password"&gt;
              &lt;/p&gt;
              &lt;p&gt;&lt;label&gt;confirm Password &amp;nbsp;&amp;nbsp; :&lt;/label&gt;
              &lt;input id="confirmpassword" name="confirmpassword" type="password"&gt;
              &lt;/p&gt;
              &lt;input type="submit" name="submit" value="register" class="btn register"&gt;
              &lt;a class="btn" href="login.php"&gt;Login&lt;/a&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>