Forum Moderators: bakedjake

Message Too Old, No Replies

mySQL on Fedora

Insert Into

         

mclethe

3:04 pm on Mar 8, 2006 (gmt 0)

10+ Year Member


Hi all,

Everything is working correctly except:
1. The use of $rq = "INSERT INTO table etc.
$result = mysql query($rq) etc.

gives me "syntax error".

2. the simple "Insert Into" is working but after correct insertion of the datas, the next "Insert Into" gives me "error double key".
auto increment for identification no is activated.

Can anyone help? URGENT, thank you.

moltar

3:28 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you having a syntax error then posting an entire INSERT INTO statement would be helpful. We really can't guess what you are doing.

mclethe

11:12 am on Mar 9, 2006 (gmt 0)

10+ Year Member


Ok, here the syntax:

$rq = "INSERT INTO table ()
VALUES ('', ' ')";
$result = mysql_query($rq)
or die ("Exécution de la requête impossible"[smilestopper]);

that returns
Erreur 1064: You have an error in your SQL syntax near '$rq = "INSERT INTO table (nom,prenom,login) VALUES (''' at line 1

As far as I know there are no forbidden names in it. The auto-increment is activated for an id-n°.

And if I use INSERT INTO table(" "[smilestopper])
VALUES (" "[smilestopper])

it works correctly... But trying to insert a new line, it returns me

Erreur 1062: Duplicate entry '' for key 2
and it doesn't show the new line in PHPAdmin.

Hope anyone can help.

moltar

11:34 am on Mar 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try to use the full INSERT syntax and use NULL, not '' in place of the field value that should auto-increment:

INSERT INTO table (nom, prenom, login) VALUES (NULL, 'one', 'two')

You were supplying an emtpry bracket, I don't think that's the correct syntax.

mclethe

12:54 pm on Mar 9, 2006 (gmt 0)

10+ Year Member



$rq = "INSERT INTO tableName (nom,prenom,login)
VALUES ('','','')";
$result = mysql_query($rq)
or die ("Exécution de la requête impossible."[smilestopper]);

I rechecked, still "syntax error n° 1064", and for else doule key.

mclethe

12:56 pm on Mar 9, 2006 (gmt 0)

10+ Year Member


By the way, use the correct brackets but here they supply else

mclethe

12:57 pm on Mar 9, 2006 (gmt 0)

10+ Year Member


better:
$rq = "INSERT INTO RIVERSIDE (nom,prenom,login)
VALUES (' ',' ',' ')";
$result = mysql_query($rq)
or die ("Exécution de la requête impossible."[smilestopper]);

moltar

3:29 pm on Mar 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you post the exact table structure and the exact query you are trying to run?

Also table names are case sensetive...