title: " ' " removes previous field data
body: <p>I'm missing something here.  You can see that I get info from a text file that's comma separated.  The insert works fine until it reaches a point where the 2nd variable <code>$player_id</code> is empty.  If it's empty, then the <code>$town_name</code> throws an error.  If it's not empty, and the <code>$town_name</code> has a string with <code>.</code> or other characters, it fails and for some reason, it acts as if <code>$player_id</code> is empty!</p>
  
  <p><strong>What am I missing!?</strong></p>
  
  <p>Terribly sorry.  Here is the response I get from the code as-is:</p>
  
  <blockquote>
    <p>75767, , 1.+Harlekus%27s+city, 519, 851, 5, 414 </p>
    
    <p>Invalid query: You have an error in your SQL syntax; check the manual
    that corresponds to your MySQL server version for the right syntax to
    use near ' '1.+Harlekus%27s+city', 519, 851, 5, 414 )' at line 2</p>
  </blockquote>
  
  <p>And here is the code I get when I remove "'".mysql_real_escape_string($town_name)."'" and just replace it with mysql_real_escape_string($town_name):</p>
  
  <blockquote>
    <p>80290, 2299128, Spencer, 414, 371, 0, 3633  Invalid query: Unknown
    column 'Spencer' in 'field list'</p>
  </blockquote>
  
  <pre><code>mysql_select_db($database_connI, $connI);
  ini_set("memory_limit","100M");
  mysql_query("towns");
  $datafile = gzfile('towns.txt.gz');
  if(!is_array($datafile)) die("File could not be opened");
  
  foreach($datafile as $datum){
      list($town_id, $player_id, $town_name, $island_x, $island_y, $number_on_island, $points) = explode(',', $datum);
  
  if(is_null($player_id)) {
      $player_id = 0;
  }
  
  
      $protectedInsert = sprintf('INSERT INTO towns (`town_id`,`player_id`,`town_name`,`island_x`,`island_y`,`number_on_island`,`town_points`)
          VALUES (%s, %s, %s, %s, %s, %s, %s)',
          $town_id, 
              $player_id,
              "'".mysql_real_escape_string($town_name)."'",
              $island_x,
              $island_y, 
              $number_on_island, 
              $points);
  
      $freed = mysql_query("TRUNCATE towns");// empty the table before inserting the new data
      $result = mysql_query($protectedInsert);//Re-fill the table with updated data
      if (!$result) {
      print"$town_id, $player_id, $town_name, $island_x, $island_y, $number_on_island, $points &lt;br&gt;&lt;br&gt;";
          print"$INSERT &lt;br&gt;&lt;br&gt;";
          die('Invalid query: ' . mysql_error());
      }
  }
  print "The database has been updated";
  mysql_close($dbh);
  </code></pre>