title: Adding data to PostgreSQL via form. Add fails if variable null/empty, how do I prevent this?
body: <p>I'm adding data to a PostgreSQL database via a PHP form. It all feels a bit sketchy. My main concern is that; in the event of a variable being null/empty the add fails. How do I prevent this? </p>
  
  <p>The simplified code is like this:</p>
  
  <pre><code>$name = $_POST['name'];
  $movie = $_POST['movie'];
  $query = "INSERT INTO data.base(name, movie) VALUES('" . $name . "', '" . $movie . "')";
  $result = pg_query($query);
  if ( $result ) {
      echo 'Thanks';
  } else {
      echo 'Error';
  }
  </code></pre>
  
  <p>So if the <code>$movie</code> variable is null/empty the whole add fails.</p>
  
  <p>I could do something like this I suppose:</p>
  
  <pre><code>$name = $_POST['name'];
  if ( ! $name ) {
      $name = '0';
  }
  </code></pre>
  
  <p>But I'd rather keep the cell empty as opposed to inserting false data.</p>
  
  <p>Any help would be much appreciated.</p>