Re: Problems with INSERT
Haig Dedeyan (Home) wrote: Hi everyone, I'm a dbase rookie and I've ran into a small problem. I created a basic faq table and all is fine regarding displaying & searching the Q & A's on a web page. Up until now, I;ve entered all Q & A's from phpMyAdmin. I'm trying to create an admin page to enter the Q & A's and for the most part, it's working. However, I keep getting the following 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 's resources than dual monitor mode to generate the video output. Running in dual' at line 2 when I try to add: Note : Single-monitor mode uses more of your computer's resources than dual monitor mode to generate the video output. Running in dual monitor mode is recommended because it is more efficient. My PHP code to add Q & A is: mysql_query("INSERT INTO faqs (Question, Answer, Category, Date) VALUES('$question', '$answer', '$category', CURDATE() ) ") or die(mysql_error()); If I enter the above text directly intophpMyAdmin, all is fine. Firstly more people will see your question if you create a new thread instead of replying to an old one. The query is getting a double quote, one from: '$answer' and one from within answer, so the query is becoming: 'single monitor computer's ' - the extra quote takes it out of the field and causes an sql error as you see. Try using http://php.net/mysql_real_escape_string or http://php.net/mysql_escape_string: $query = "insert into faqs(question, answer, category, date) values ('" . mysql_real_escape_string($question) . "', '" . mysql_real_escape_string($answer) ... mysql_query($query); -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Problems with INSERT
[EMAIL PROTECTED] wrote: > I keep getting the following 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 's > resources than dual monitor mode to generate the video output. Running > in dual' at line 2 > > when I try to add: > > Note : Single-monitor mode uses more of your computer's resources than > dual monitor mode to generate the video output. Running in dual monitor > mode is recommended because it is more efficient. > > > My PHP code to add Q & A is: > > mysql_query("INSERT INTO faqs > (Question, Answer, Category, Date) VALUES('$question', '$answer', > '$category', CURDATE() ) ") > or die(mysql_error()); > > If I enter the above text directly intophpMyAdmin, all is fine. > > Any help is greatly appreciated. > > Thanks > > Haig Haig, $questionEscaped = mysql_real_escape_string($question); mysql_query("INSERT INTO faqs (Question, Answer, Category, Date) VALUES('*$questionEscaped*', '$answer', '$category', CURDATE() ) ") or die(mysql_error()); You need to escape the single quote in your FAQ. David Thanks guys for all your input. Greatly appreciated!! Escaping the single quotes did the trick. Haig -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Problems with INSERT
> I keep getting the following 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 's > resources than dual monitor mode to generate the video output. Running > in dual' at line 2 > > when I try to add: > > Note : Single-monitor mode uses more of your computer's resources than > dual monitor mode to generate the video output. Running in dual monitor > mode is recommended because it is more efficient. > > > My PHP code to add Q & A is: > > mysql_query("INSERT INTO faqs > (Question, Answer, Category, Date) VALUES('$question', '$answer', > '$category', CURDATE() ) ") > or die(mysql_error()); > > If I enter the above text directly intophpMyAdmin, all is fine. > > Any help is greatly appreciated. > > Thanks > > Haig Haig, $questionEscaped = mysql_real_escape_string($question); mysql_query("INSERT INTO faqs (Question, Answer, Category, Date) VALUES('$questionEscaped', '$answer', '$category', CURDATE() ) ") or die(mysql_error()); You need to escape the single quote in your FAQ. David
RE: Problems with INSERT
[snip] 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 's resources than dual monitor mode to generate the video output. Running in dual' at line 2 when I try to add: Note : Single-monitor mode uses more of your computer's resources than dual monitor mode to generate the video output. Running in dual monitor mode is recommended because it is more efficient. My PHP code to add Q & A is: mysql_query("INSERT INTO faqs (Question, Answer, Category, Date) VALUES('$question', '$answer', '$category', CURDATE() ) ") or die(mysql_error()); [/snip] You need to escape your $question and $answer variables, the apostrophe's contained there are goofing you up. http://www.php.net/mysqlrealescapestring -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: problems with insert
I don't the language your using but it looks like you may have left out a comma. I find it difficult to know what is going on with your code without knowing the content of your variables. Could you provide us with the contents of strbuf, before it is passed to mysql!? - Original Message - From: "jarle rudihagen" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, February 27, 2001 6:50 Subject: problems with insert > I got a mysql table with to collumns: imageID(integer) and imageData(blob). > > I'm using the mysql++ API. > > I can't seem to insert both the imageID and imageData into the table. When > I'm just inserting the imageData(the blob field) it works out fine. But as > soon as I try to pass both fields, things crash. > > My coding: > string fill(read_buffer,blen); > strbuf << "INSERT INTO " << MY_TABLE << "values(" << argv[2] << "\"" << > escape << fill << "\")"; > query.exec(strbuf.str()); > > The following message apear: > [jarle@biri2 jarle]$ ./test_mysql_image "essolog.gif" > "/home/jarle/essolog.gif" "2" > Error: You have an error in your SQL syntax near > '/home/jarle/essolog.gif"GIF89a\\\0>\0Õ\0\0ó÷úÞYoþèì$a¢åíô7oª®ÅÜCw®ZÏ > > can anybody help me??? > > /Jarle > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php