title: How to Post in the Same Page in Simple PHP?
body: <p>I am trying to create a Registration System using only PHP. This is an example of that. But I think I have done something wrong. I tried to find similar solution in StackOverFlow posts but didn't get any exact solution. It would be really get if someone would help me to find the error in my code below.</p>
  
  <pre><code>&lt;?php
  // POST HANDLER --&gt;
  
  if(isset($_POST['registerForm']))
  {
      conFunc(); // Connection Function
  
      $userid = $_POST['userid'];
      $name = $_POST['name'];
  
      $getUserId = mysql_query("SELECT * FROM `user` WHERE `userid` = '".$userid."'");
      $id = mysql_fetch_array($getUserId);
  
      if($id)
      {
          echo "This User ID is Already Available on the System, Please Choose Something Else!";
      }
      else
      {
  
          $query = mysql_query("INSERT INTO `user` (`userid`, `name`");
  
          if($query)
          {
              echo "A New User is Registered Successfully:&lt;br /&gt;&lt;br /&gt;";
              echo "&lt;b&gt;User ID:&lt;/b&gt; " . $userid . "&lt;br /&gt;";
              echo "&lt;b&gt;User Name:&lt;/b&gt; " . $name . "&lt;br /&gt;";
          }
          else
          {
              echo "There is an Error while Saving: " . mysql_error();
              echo "&lt;br /&gt;Please click on Create User from menu, and try again&lt;br /&gt;&lt;br /&gt;.";
          }
  
      }
      exit;
  }
  // POST HANDLER --&gt;
  ?&gt;
  
  &lt;!-- FORM GOES BELOW --&gt;
  
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="post" name="registerForm"&gt;
  
  &lt;table style="width: 100%"&gt;
      &lt;tr&gt;
          &lt;td&gt;User ID&lt;/td&gt;
          &lt;td&gt;&lt;input name="userid" type="text" style="width: 300px" /&gt;&lt;br /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Name&lt;/td&gt;
          &lt;td&gt;&lt;input name="name" type="text" style="width: 300px" /&gt;&lt;br /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input style="width: 130px; height: 30px" type="submit" name="submit" value="Register Now" /&gt;&lt;br /&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/form&gt;
  </code></pre>