title: How to use $_SERVER['PHP_SELF']?
body: <p>Hi I made this very simple registration page I have 3 files: welcome.php, registration_form.php, and register.php</p>
  
  <p>This is my code for welcome.php</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;h1&gt;WELCOME!&lt;/h1&gt;
  
  &lt;form action="login.php" method="POST"&gt;
  
  &lt;p&gt;Username: &lt;input type="text" name="login_username" value=""&gt;         &lt;/p&gt;
  &lt;p&gt;Password: &lt;input type="password" name="login_password" value=""&gt;&lt;/p&gt;
  &lt;p&gt;&lt;input type="submit" value="LOGIN" name="login" size="20"&gt;&lt;/p&gt;
  
  &lt;a href="registration_form.php"&gt;Register for new account&lt;/a&gt;
  
  &lt;/body&gt;
  &lt;html&gt;
  </code></pre>
  
  <p>This is my code in registration_form.php</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Register here&lt;/h1&gt;
  
  &lt;form action="register.php" method="POST"&gt;
  
  &lt;p&gt;Username: &lt;input type="text" name="register_username" value=""&gt;&lt;/p&gt;
  &lt;p&gt;Password: &lt;input type="password" name="register_password" value=""&gt;&lt;/p&gt;
  &lt;p&gt;Re-type Password: &lt;input type="password" name="register_repassword" value=""&gt;&lt;/p&gt;
  &lt;p&gt;E-mail Address: &lt;input type="text" name="register_email" value=""&gt;&lt;/p&gt;
  &lt;p&gt;Re-type E-mail Address: &lt;input type="text" name="register_reemail" value=""&gt;&lt;/p&gt;
  &lt;p&gt;&lt;input type="submit" value="Register" name="register"&gt;&lt;/p&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;html&gt;
  </code></pre>
  
  <p>This is my register.php</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;?php
  ob_start();
  
  //=======================database variables
  $host="localhost";
  $db_username="root";
  $db_password="";
  $db="forum_members";
  $db_table="members";
  
  //=======================connect to database
  mysql_connect("$host","$db_username","$db_password") or die("Could not connect to the database!");
  mysql_select_db("$db") or die("database not found!");
  
  
  //form variables
  $register_user=$_POST['register_username'];
  $register_pass=$_POST['register_password'];
  $register_repass = $_POST['register_repassword'];
  $register_email=$_POST['register_email'];
  $register_reemail=$_POST['register_reemail'];
  
  //protect database from MySQL database
  $register_user=stripslashes($register_user);
  $register_pass=stripslashes($register_pass);
  $register_repass=stripslashes($register_repass);
  $register_email=stripslashes($register_email);
  $register_reemail=stripslashes($register_reemail);
  $register_user=mysql_real_escape_string($register_user);
  $register_pass=mysql_real_escape_string($register_pass);
  $register_repass=mysql_real_escape_string($register_repass);
  $register_email=mysql_real_escape_string($register_email);
  $register_reemail=mysql_real_escape_string($register_reemail);
  
  //check required fields
  if (empty($register_user) || empty($register_pass)) {
  echo "Please fill the required fields";
  die();
  }
  
  if (empty($register_repass) || empty($register_email)) {
  echo "Please fill the required fields";
  die();
  }
  if (empty($register_reemail)) {
  echo "Please fill the required fields";
  die();
  }
  
  //check if username has alphanumeric characters only
  if (!preg_match("/^[a-zA-Z0-9_]+$/", $register_user) || !preg_match("/^[a-zA-Z0-9_]+$/",     $register_pass)) {
  echo "Username and Password can only contain alphanumeric characters";
  die();
  }
  
  //check username and password minimum length
  if (strlen($register_user) &lt; 4) {
  echo "Username must be more than 4 characters!";
  die();
  }
  
  if (strlen($register_pass) &lt; 8) {
  echo "Password must be at least 8 characters!";
  die();
  }
  
  if ($register_pass !== $register_repass) {
  echo "Your password did not match";
  die();
  }
  
  if ($register_email !== $register_reemail) {
  echo "Your E-mail address did not match";
  die();
  }
  
  //check duplicate username
  $duplicate_user="SELECT * FROM $db_table WHERE username='$register_user'";
  $execute_duplicate=mysql_query($duplicate_user);
  $duplicate_result = mysql_num_rows($execute_duplicate);
  if ($duplicate_result == 1) {
  echo "This username is already used";
  die();
  }
  
  //create MySQL Query
  $query_insert="INSERT INTO $db_table(username, password, email) VALUES ('$register_user', '$register_pass', '$register_email')";
  
  //execute MySQL query
  $execute_insert=mysql_query($query_insert);
  //$execute_insert=mysql_query($query_insert);
  
  //check inserted data
  $check_insert="SELECT * FROM $db_table WHERE username='$register_user'";
  $execute_insert1=mysql_query($check_insert);
  $verify_insert=mysql_num_rows($execute_insert1);
  
  if ($verify_insert==1) {
  echo "Registration Successful! You may now login";
  }
  else {
  echo "Registration Failed!";
  }
  
  ob_end_flush();
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My question is how can I use $_SERVER['PHP_SELF'] so that I can merge registration_form.php and register.php? So that I won't be working on multiple files. My goal is to display "Registration successful! You may now login" or "Registration failed" at the same page(preferably at the top) and when a guest didn't enter any information and clicked the 'register' button' it will go back to the registration form as if nothing happens. I tried to look for an answer in google, but it doesn't work.</p>
  
  <p>P.S. I know there are a lot of flaws in my code, please be good. I'm just starting in studying php.</p>