title: PHP not inserting some values into MySQL database
body: <p>I have an HTML form which submits values to the following PHP file, which inserts them into a MySQL database:</p>
  
  <pre><code>&lt;?php
    $con = mysql_connect("*","*","*");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
  
    mysql_select_db("*", $con);
  
    $sql="INSERT INTO scores (hometeam, awayteam, result)
    VALUES
    ('" . mysql_real_escape_string($_POST['hometeam']) . "',
     '" . mysql_real_escape_string($_POST['awayteam']) . "',
     '" . mysql_real_escape_string($_POST['result']) . "')";
  
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
  
    mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>Sometimes an input field in the HTML form will be left blank and in this case I do not want anything inserted into the database. I want the value to remain <em>NULL</em>. At the moment when I fill in my form like this:</p>
  
  <p>Home team: Blue team<br>
  Away team: [blank]<br>
  Result: Won<br></p>
  
  <p>The following is inserted into my database:</p>
  
  <p>Home team: Blue team<br>
  Away team: ' '<br>
  Result: Won<br></p>
  
  <p>What I want to be inserted/not inserted is:</p>
  
  <p>Home team: Blue team<br>
  Away team: <em>NULL</em><br>
  Result: Won<br></p>
  
  <p>I've hunted hours for a solution. Can anyone help? Thank you.</p>