Jump to content

Recommended Posts

This seems impossible to fix but i kno its probably going to be simple i just cannot figure it out to save my life.

 

My 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: 't even gotta wonder
I was voted number one rapper to drop 

 

My code:

$sql = "INSERT INTO `$table` VALUES ('$pc', '$pBy', '$email', '$lyric', '$song', '$artist', '$date','','')";
mysql_query($sql);

 

Now, i know the problem i just cannot solve it... Theres a problem when i enclose the $lyric var with ' and ' but, i've tried enclosing it with everything possible even \" but it just does not want to execute.

 

Any help on this problem would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/38852-mysql-syntax-error/
Share on other sites

You don't need to know the structure...you can jump directly to VALUES if each value corresponds to your table structure. Try enclosing the $table in '{$table}' instead. You don't really need the 's there unless you have a weird table name. So try {$table} too..

Link to comment
https://forums.phpfreaks.com/topic/38852-mysql-syntax-error/#findComment-186824
Share on other sites

I've tried

$sql = "INSERT INTO `$table` (pc, pBy, email, lyric, song, artist, date) VALUES ('$pc', '$pBy', '$email', '$lyric', '$song', '$artist', '$date','','')";
mysql_query($sql);

 

And i've also tried {$table}

 

no luck... i appreciate all of the help :D

Link to comment
https://forums.phpfreaks.com/topic/38852-mysql-syntax-error/#findComment-186827
Share on other sites

The lyric var is:  FIELD:lyric  TYPE:blob  ATTRIBUTES:BINARY  NULL:No 

in phpmyadmin.

 

But its technically song lyrics so basic text and chars such as: ' " [ ] etc.

 

Thats what that var ($lyric) contains.

 

The $table var just contains the table name (Lyrics_01) thats all that var contains, the var that has a problem is $lyric.

$table="lyrics_01";

 

Heres the link if you can figure it out that way, click Add Lyric at the top.

 

http://patricks.kicks-ass.net/lyrics/

Link to comment
https://forums.phpfreaks.com/topic/38852-mysql-syntax-error/#findComment-186836
Share on other sites

are those back tick's you are using for $table? try using just regular '

 

If you are going to wrap a table or column name in anything it has to be a back-tic....as stated on this page in the mysql manual:

 

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html#id2817618

Link to comment
https://forums.phpfreaks.com/topic/38852-mysql-syntax-error/#findComment-186838
Share on other sites

$lyric = mysql_real_escape_string($lyric);

$sql = "INSERT INTO `$table` VALUES ('$pc', '$pBy', '$email', '$lyric', '$song', '$artist', '$date','','')";

mysql_query($sql);

 

Problem solved, thank you very much now i need to research mysql_real_escape_string to see exactly what that does so i understand whats going on, haha thanks alot man!

Link to comment
https://forums.phpfreaks.com/topic/38852-mysql-syntax-error/#findComment-186840
Share on other sites

No, you should use the database specific functions. If you're using mysql, use the mysql functions.

http://us3.php.net/manual/en/security.database.sql-injection.php

"Quote each non numeric user supplied value that is passed to the database with the database-specific string escape function"

Link to comment
https://forums.phpfreaks.com/topic/38852-mysql-syntax-error/#findComment-186856
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.