title: Error: 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 '
body: <p>The code below is used when the user enters a youtube url it get the youtube id from the url. It then get the title for that video with that id. That is then inserted into a database and recalled to display the image of the video associated with that id.</p>
  
  <p>if i use this youtube url <a href="http://www.youtube.com/watch?v=p64tAbP-nHE" rel="nofollow">http://www.youtube.com/watch?v=p64tAbP-nHE</a> or and other youtube url. If the title of that youtube url contains a ' ie(2013 Ravens Rock Rally - Jonathan O'Callaghan &amp; Gavin Sheehan - Stage 3) i get the error</p>
  
  <p>Error: 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 'Callaghan &amp; Gavin Sheehan - Stage 3'' at line 1</p>
  
  <p>Any help would be great, thanks in advance.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  include 'dataconnection.php';
  // Check connection
  if (mysqli_connect_errno())
      {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
      else        
          $url = $_POST['set_video'];
          parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
  
          $youtube_id = $my_array_of_vars['v'];
  
          $info = $_POST['set_desc'];
  
          $id = $my_array_of_vars['v'];
          $xmlData =  simplexml_load_string(file_get_contents("http://gdata.youtube.com/feeds/api/videos/{$id}?fields=title"));
  
          $title = (string)$xmlData-&gt;title;
  
          $sql="INSERT INTO videodetails SET id='null',youtube_id='$youtube_id',info='$title'";
  
          if (!mysqli_query($connection,$sql))
            {
            die('Error: ' . mysqli_error($connection)); 
            }
          echo "&lt;div id='pageheader'&gt;
                  1 record added&lt;span id='logout'&gt;Return to &lt;a href='contributors_login.html'&gt;Contributors Login&lt;/a&gt;&lt;/span&gt;  
               &lt;/div&gt;";
  
          echo '&lt;div id="setvideo"&gt;&lt;a href="http://www.youtube.com/watch?v='.$my_array_of_vars['v'].'" target="_blank"&gt;&lt;img src="http://i4.ytimg.com/vi/'.$my_array_of_vars['v'].'/default.jpg" style="border:solid 2px white;"&gt;&lt;/a&gt;&lt;p&gt;'.$title.'&lt;/p&gt;&lt;/div&gt;';
  
      mysqli_close($connection);  
  ?&gt;
  </code></pre>