Click here to get back home

Error in INSERT

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Error in INSERT =?ISO-8859-1?B?UOlw6g==?= 06-24-2008
Get Chitika Premium
Posted by =?ISO-8859-1?B?UOlw6g==?= on June 24, 2008, 12:41 pm
Please log in for more thread options
I have a page that inserts these values in the table...

                                        $fundo_nome = $_POST['fundo_nome'];
                                        $fundo_link = $_POST['fundo_link'];
                                        $fundo_activo = $_POST['fundo_activo'];

                                        $sql = sprintf("INSERT INTO relatorio_fundo(fundo_nome,
fundo_link, fundo_activo) VALUES (%s, %s, %s)",
                                        mysql_real_escape_string($fundo_nome),
                                        mysql_real_escape_string($fundo_link),
                                        mysql_real_escape_string($fundo_activo));


THen the error appears...:

Invalid query: 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 ' , )' at line 1


Can anyone help???

Posted by Iván Sánchez on June 24, 2008, 12:57 pm
Please log in for more thread options
Pépê wrote:

> Invalid query: 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 ' , )' at line 1

Enclose any string literals in your SQL query in quotes, and (as this is a
SQL question), ask in a SQL or DB newsgroup, not a PHP newsgroup.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.

Posted by Peter H. Coffin on June 24, 2008, 2:10 pm
Please log in for more thread options
On Tue, 24 Jun 2008 09:41:29 -0700 (PDT), Pépê wrote:
> I have a page that inserts these values in the table...
>
>                                         $fundo_nome = $_POST['fundo_nome'];
>                                         $fundo_link = $_POST['fundo_link'];
>                                         $fundo_activo = $_POST['fundo_activo'];
>
>                                         $sql = sprintf("INSERT INTO relatorio_fundo(fundo_nome,
> fundo_link, fundo_activo) VALUES (%s, %s, %s)",
>                                         mysql_real_escape_string($fundo_nome),
>                                         mysql_real_escape_string($fundo_link),
>                                         mysql_real_escape_string($fundo_activo));
>
>
> THen the error appears...:
>
> Invalid query: 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 ' , )' at line 1

It's ultimately going to be a comp.databases.mysql question instead,
but the FIRST debugging step for this kind of problem is to print out
what's in $sql before you run the query. If the answer isn't obvious
from looking at the query, ask on the other newsgroup, showing the
contents of $sql.

--
The Web brings people together because no matter what kind of a twisted
sexual mutant you happen to be, you've got millions of pals out there.
Type in 'Find people that have sex with goats that are on fire' and the
computer will ask, 'Specify type of goat.' -- Rich Jeni

Posted by Jeff on June 24, 2008, 2:38 pm
Please log in for more thread options
Peter H. Coffin wrote:
> On Tue, 24 Jun 2008 09:41:29 -0700 (PDT), Pépê wrote:
>> I have a page that inserts these values in the table...
>>
>>                                         $fundo_nome = $_POST['fundo_nome'];
>>                                         $fundo_link = $_POST['fundo_link'];
>>                                         $fundo_activo = $_POST['fundo_activo'];
>>
>>                                         $sql = sprintf("INSERT INTO relatorio_fundo(fundo_nome,
>> fundo_link, fundo_activo) VALUES (%s, %s, %s)",
>>                                         mysql_real_escape_string($fundo_nome),
>>                                         mysql_real_escape_string($fundo_link),
>>                                         mysql_real_escape_string($fundo_activo));
>>
>>
>> THen the error appears...:
>>
>> Invalid query: 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 ' , )' at line 1
>
> It's ultimately going to be a comp.databases.mysql question instead,
> but the FIRST debugging step for this kind of problem is to print out
> what's in $sql before you run the query. If the answer isn't obvious
> from looking at the query, ask on the other newsgroup, showing the
> contents of $sql.
>
This seems like a lot of work and it's still susceptible to a stray
single quote.

What possible advantage does this coding style have over the simpler
PDO with prepare and placeholders?

Jeff

Posted by Peter H. Coffin on June 24, 2008, 3:18 pm
Please log in for more thread options
On Tue, 24 Jun 2008 14:38:19 -0400, Jeff wrote:
> Peter H. Coffin wrote:
>> On Tue, 24 Jun 2008 09:41:29 -0700 (PDT), Pépê wrote:
>> [...]
>> It's ultimately going to be a comp.databases.mysql question instead,
>> but the FIRST debugging step for this kind of problem is to print out
>> what's in $sql before you run the query. If the answer isn't obvious
>> from looking at the query, ask on the other newsgroup, showing the
>> contents of $sql.
>>
> This seems like a lot of work and it's still susceptible to a stray
> single quote.
>
> What possible advantage does this coding style have over the simpler
> PDO with prepare and placeholders?

Pointing at the wrong post before following up? (:

print $sql;

doesn't seem too complicated...

--
60. My five-year-old child advisor will also be asked to decipher any code I
am thinking of using. If he breaks the code in under 30 seconds, it will
not be used. Note: this also applies to passwords.
--Peter Anspach's list of things to do as an Evil Overlord

Similar ThreadsPosted
MySQL INSERT error February 20, 2006, 1:33 pm
insert (now(),now(),....) March 21, 2005, 11:53 am
Why does this insert twice? September 4, 2005, 12:17 pm
PHP insert October 20, 2006, 1:55 pm
no insert ... December 17, 2006, 6:17 pm
sql insert question October 12, 2004, 11:46 am
Insert Spaces November 26, 2004, 3:52 am
try to insert data... May 14, 2005, 2:58 pm
insert ignore October 6, 2005, 7:10 pm
INSERT OR UPDATE? October 8, 2005, 11:15 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap