title: Comparing a php variable and mysql table element that has backslashes
body: <p>I'm trying to create an online database of the music I locally have on my computer.  I already have a table of every song in my library and would like to create a different table with just the song ID's (auto-incremented when I added the songs to my main table) that act as one of my playlists.  </p>
  
  <p>From what I can tell, the only 100% certifiable method for matching the songs is by the location on my disk ( C:\Users\username\Music\iTunes\iTunes Media\Music\Jonathan Coulton and GLaDOS\Portal\128 128 Still Alive Duet.mp3 ) as an example.  In my PHP code I get the song location into a variable and if I print it relative to the equivalent song location in my MYSql table, they match up exactly but when I try to run a select statement using that, it gives me an error.  From what I can tell this is being caused by the backslashes in the location info. </p>
  
  <p>This is the select statement I'm using, </p>
  
  <pre><code>SELECT id FROM itunes WHERE Location=$locationval
  </code></pre>
  
  <p>where $locationval is the current song's location, id is the autoincremented id in my main table, and itunes is my main table.</p>
  
  <p>Is there any way around this?  And as I am a beginner, is the backslashes really the issue?</p>
  
  <p>For reference here is the full code for importing the playlist, its using the DB plugin for PEAR (a PHP extension).</p>
  
  <pre><code>&lt;?php
  
  // define table name
  define('TABLE_NAME', 'playlist');
  
  // create database connection
  require_once('DB.php');
  $dsn = 'mysql://username:password@localhost/itunes';
  $DB =&amp; DB::connect($dsn);
  if (DB::isError($DB)) {
    die($DB-&gt;getMessage());
  }
  $DB-&gt;setFetchMode(DB_FETCHMODE_ASSOC);
  
  // load text file
  $file = file_get_contents('Portal.txt');
  
  // explode on new line
  $file = explode("\r", $file);
  set_time_limit(0);
  
  
  // loop through each line in the file
  foreach ($file as $key =&gt; $value) {
  
    // explode on tab to get column list
    $exploded = explode("\t", $value);
  
    // check for first row, which contains column headers
    if ($key == 0) {
  
   }
     else{
  
      if(count($exploded)&gt;3)
      {
      $locationval=$exploded[26];
    echo $exploded[26];
    echo "&lt;br /&gt;";
    $result = mysql_query("SELECT id FROM itunes WHERE Location=$locationval");
    //$result = mysql_query("SELECT * FROM itunes WHERE id=8292");
  set_time_limit(0);
  $row = mysql_fetch_row($result);
    //test statements to see if the query worked
    echo "Test: ";
    echo $row['id'];
    echo $row['Location'];    
    echo "&lt;br /&gt;";
  
    }
    }
  
  }
  ?&gt;
  </code></pre>
  
  <p>Which was modified from the code here: <a href="http://ericlondon.com/posts/208-exporting-itunes-data-into-mysql-and-creating-sql-to-show-top-rated-albums" rel="nofollow">http://ericlondon.com/posts/208-exporting-itunes-data-into-mysql-and-creating-sql-to-show-top-rated-albums</a></p>
  
  <p>If any more info is needed, please let me know.</p>