title: Auto Login after Registeration PHP
body: <p>I have a problem in auto login to my-account page after registration. Please help, here is my code. I am trying to login user without any email confirmation.</p>
  
  <pre><code> &lt;?php
      @ob_start();session_start();
  
      if($_SESSION['LOGIN_ID'] &gt; 0)
      header("location:myaccount.php");   
  
      $invalidcaptcha = 0;
      if($_POST['register_submit'])
      {
  
          $ip = getIP();      
          $emailid = $_POST['emailid'];
          $pwd = $_POST['pwd'];
          $confirm = '1';
          $blocked = '0';
          $ccode = base64_encode($email);
  
          $ures = mysql_query("select id from user where emailid='".mysql_real_escape_string($_POST['emailid'])."'");
          if(mysql_num_rows($ures) &gt; 0 )
          {
              header("location:login.php?emailexist=1");  
          }
          else if($_POST['security_code']==$_SESSION['freecap_word_hash']) 
          {       
              mysql_query("insert into user set emailid='".mysql_real_escape_string($emailid)."',pwd='".md5($pwd)."',blocked='".$blocked."',confirm='".$confirm."',ccode='".$ccode."',reg_date=now(),reg_ip='".$ip."'");
              $i_id = mysql_insert_id();
  
               $res=mysql_query("SELECT id, emailid, pwd FROM users WHERE emailid='$emailid'");
         $row=mysql_fetch_array($res);
         $count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row
  
          $_SESSION['LOGIN_ID'] = $row['userId'];
          header("Location: myaccount.php");
  
          }
  
      }
  
      ?&gt;
  </code></pre>