Jump to content


Photo

Writing a database query script


  • Please log in to reply
6 replies to this topic

#1 Justinx89x

Justinx89x
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 23 April 2006 - 10:40 PM

I am having problems with this line of my script...
// Performing SQL query
        $query = "INSERT INTO nuke_audio_audio ('title', 'url', 'artist') VALUES ('$arrArtistTitle[1]', 'http://www.dxcr.com/audio/tones/$filename', '$arrArtistTitle[0]'";
        echo $result = mysql_query($query) or die('Query failed: ' . mysql_error());

I get an error that says...
Query failed: 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 ''title', 'url', 'artist') VALUES

The script I am making takes a bunch of music files and puts them into a database

#2 shimano55

shimano55
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationLos Angeles, CA

Posted 23 April 2006 - 10:44 PM

Take out the single quotes around title, url, and artist.

By the way, you also need to add another ) after '$arrArtistTitle[0]'.
PHP is my life.

#3 Justinx89x

Justinx89x
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 23 April 2006 - 10:50 PM

[!--quoteo(post=367798:date=Apr 23 2006, 06:44 PM:name=shimano55)--][div class=\'quotetop\']QUOTE(shimano55 @ Apr 23 2006, 06:44 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Take out the single quotes around title, url, and artist.

By the way, you also need to add another ) after '$arrArtistTitle[0]'.
[/quote]

Thanks for your help, but now I am recieving another error. It says...
Query failed: 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 've Got)', 'http://www.dxcr.com/audio/tones/A Tribe Called Quest

#4 shimano55

shimano55
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationLos Angeles, CA

Posted 23 April 2006 - 10:53 PM

Did you add the )????

Your code should look like:
// Performing SQL query
        $query = "INSERT INTO nuke_audio_audio (title, url, artist) VALUES ('$arrArtistTitle[1]', 'http://www.dxcr.com/audio/tones/$filename', '$arrArtistTitle[0]')";
        echo $result = mysql_query($query) or die('Query failed: ' . mysql_error());

Is that how it looks?

-shimano55
PHP is my life.

#5 Justinx89x

Justinx89x
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 23 April 2006 - 10:55 PM

[!--quoteo(post=367800:date=Apr 23 2006, 06:53 PM:name=shimano55)--][div class=\'quotetop\']QUOTE(shimano55 @ Apr 23 2006, 06:53 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Did you add the )????

Your code should look like:
// Performing SQL query
        $query = "INSERT INTO nuke_audio_audio (title, url, artist) VALUES ('$arrArtistTitle[1]', 'http://www.dxcr.com/audio/tones/$filename', '$arrArtistTitle[0]')";
        echo $result = mysql_query($query) or die('Query failed: ' . mysql_error());

Is that how it looks?

-shimano55
[/quote]

Yeah that fixed the problem, I realized that right after I posted the message. It looks like it works now, but I am now faced with another problem. My script will malfunction when it sees a single quote(') in any filename. Any ideas how to make it ignore that?

#6 shimano55

shimano55
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationLos Angeles, CA

Posted 23 April 2006 - 11:00 PM

Is the malfunction detected around the mysql_query part? Because I am skeptical about ur url declaration.

Otherwise, you usually have to escape single and double quotes. A good way to take care of this would be:
$filename = "Nirvana - Jesus Doesn't Want Me For a Sunbeam"; //notice the single quote
$filename = mysql_escape_string($filename); //this will add slashes before quotes and other special chars

That should do the trick if that's where the problem is.

-shimano55
PHP is my life.

#7 Justinx89x

Justinx89x
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 23 April 2006 - 11:11 PM

Tried that, but still it is still giving me trouble when trying to access a file that has a single quote.

Here is the error I am getting.

Query failed: 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 've Got)', 'http://www.dxcr.com/audio/tones/A Tribe Called Quest

Here is how I setup the code.

// Performing SQL query
        $query = "INSERT INTO nuke_audio_audio (title, url, artist) VALUES ('$arrArtistTitle[1]', 'http://www.dxcr.com/audio/tones/$filename', '$arrArtistTitle[0]')";
        $filename = "Nirvana - Jesus Doesn't Want Me For a Sunbeam";
        $filename = mysql_escape_string($filename);
        echo $result = mysql_query($query) or die('Query failed: ' . mysql_error());





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users