title: php: check if variable is not empty before running INSERT query
body: <p>I built a song request form for my wedding website and would like to check if the variables I am storing the form input in is empty before POST'ing to the database.  My goal is simple prevent blank rows from being added to mysql db when the for is fired off.</p>
  
  <pre><code> &lt;?php 
  // extract data from form; store in variable
  $artist =  $_POST["artist"];
  $song = $_POST["song"];
  
  // connect to server 
  $conn = mysql_connect('host', 'user', 'pass');
  
  
  // check if you can connect; if not then die
  
  if (!$conn) {
      echo "&lt;center&gt;";
      die('Could Not Connect: ' . mysql_error());
      echo "&lt;/center&gt;";
      }
  
  // check if you can select table; in not then die
  
  $db = mysql_select_db('database', $conn);
  
  if (!$db) {
      echo "&lt;center&gt;";
      die('Database Not Selected: ' . mysql_error());
      echo "&lt;/center&gt;";
      }
  
  // Define the query to inser the song request
  $insert = mysql_query("INSERT INTO Songs (Artist, Song) VALUES ('$artist', '$song')");  
  
  // check if above variables are empty 
  if (!empty($artist) and !empty($song)) {
      echo "&lt;center&gt;";
      echo "Insert was succesful&lt;br&gt;";
      echo "&lt;a href='index.html' target='_self' &gt;Back&lt;/a&gt;";
      echo "&lt;/center&gt;";
  }
  else {
      echo "&lt;center&gt;";
      die("Please fill in at least the artist name");
      echo "&lt;/center&gt;";
  }
  
  // close the connection to the server
  mysql_close($conn);
  ?&gt;
  </code></pre>
  
  <p>I have the above in a file called insert.php which is fired off when form on the index page is submitted.  Form is submitting using POST and works just fine, however I would like to prevent blank submissions from happening.</p>
  
  <p>Very new to programming and want to learn how to do this right.</p>
  
  <p>Thanks for your patience.</p>