title: Stop empty values from input boxes from being inserted into my database? PHP
body: <p>This is the html form (register.php):</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;form action="handle_registration.php" method="post"&gt;
  
  &lt;fieldset&gt;&lt;legend&gt;Enter your
  information in the form below:&lt;/legend&gt;
  
  First Name: &lt;input type="text" name="fname" size="20" maxlength="40"&gt;&lt;br&gt;
  Last Name: &lt;input type="text" name="lname" size="20" maxlength="40"&gt;&lt;br&gt;
  Username: &lt;input type="text" name="uname" size="20" maxlength="40"&gt;&lt;br&gt;
  Password: &lt;input type="text" name="pword" size="20" maxlength="40"&gt;&lt;br&gt;
  &lt;input type="submit" name="submit" value="submit my info"&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the php script that handles the registration (handle_registration.php):</p>
  
  <pre><code>&lt;?php
  
  // Create a shorthand for the form data:
  
  $fname = $_POST['fname'];
  $lname = $_POST['lname'];
  $uname = $_POST['uname'];
  $pword = $_POST['pword'];
  
  // Create the connection variables:
  
  $db_host = "localhost";
  $db_user = "root";
  $db_pass = "";
  $db_name = "registration_info";
  $con = mysqli_connect("$db_host", "$db_user", "$db_pass", "$db_name");
  
  // Check the connection:
  
  if (mysqli_connect_errno ())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  // Make sure all of the input boxes have a value:
  
  if (empty($fname)) {
  die('You forgot to enter your first name!');
  }
  
  if (empty($lname)) {
  die('You forgot to enter your last name!');
  }
  
  if (empty($uname)) {
  die('You forgot to choose a username!');
  }
  
  if (empty($pword)) {
  die('You forgot to choose a password!');
  }
  
  // Insert the data from the form into the DB:
  
  $sql = "INSERT INTO basic_information (First_Name, Last_Name, Username, Password)
  VALUES
  ('$_POST[fname]', '$_POST[lname]', '$_POST[uname]', '$_POST[pword]')";
  
  // Enter the info the end user type if everything is ok:
  
  if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
  else
  {
  echo "Record has been added";
  }
  
  // Close the connection:
  
  mysqli_close($con);
  
  ?&gt;
  </code></pre>
  
  <p>Here's the problem: </p>
  
  <p>I want to submit the entered values into my database if all of the input fields have a value, but when I use the die function after checking to see if they're empty, then it kills the script. I just want to kill the part were it inserts it into my database if one or more of the fields are empty &amp; display an error message that tells which field was empty. I'm not sure how to get around this and any help will be greatly appreciated.</p>