PDA

View Full Version : problems with inserting data


joyce
Thu 7th Feb '02, 5:05am
hi, i have 1 textfield, if user fill up all the text field, my query works well, but if user only key in a few, then i got error for my query.

can anyone tell me wat is wrong with my query?

$DB_site->query("INSERT INTO point(newthread, reply, reply1, reply2, reply3, reply4, reply5, replypoint1, replypoint2, replypoint3, replypoint4, replypoint5, view1, view2, view3, view4, view5, viewpoint1, viewpoint2, viewpoint3, viewpoint4, viewpoint5, addpoint, penalty, maxpenalty) VALUES ($anewthread, $areply, areply1, $areply2, $areply3, $areply4, $areply5, $areplypoint1, $areplypoint2, $areplypoint3, $areplypoint4, $areplypoint5, $aview1, $aview2, $aview3, $aview4, $aview5, $aviewpoint1, $aviewpoint2, $aviewpoint3, $aviewpoint4, $aviewpoint5, $aaddpoint, $apenalty, $amaxpenalty)");

scoutt
Thu 7th Feb '02, 12:40pm
sounds like your DB fields can't be null. if the user doesn't enter text in all the fields it will enter those fields in the DB as Null and if the DB is set to Not Null then that might be the case.

jeffct
Sat 9th Feb '02, 1:21am
What may be happening is when they do not fill in a field, it is coming in as NULL and this is what MySQL sees:

INSERT INTO your_table (field1, field2, field3) VALUES (1, , 2);

In that case they did not enter field2 so there is a blank spot there, MySQL is expecting data there.

Enclose each of those variables with single quotes so that MySQL knows when nothing was entered for a field:

INSERT INTO your_table (field1, field2, field3) VALUES ('$field1', '$field2', '$field3')