View Full Version : insert problem

07-26-2006, 03:26 PM
Having entered data to a form and then submitted it, the form script re-runs with the 'submitToDb sub-routine.

I want this sub routine fristly, to write to the Db, creating a new record and adding the form data.

This, however, doesn't seem to do it so can you please help. BTW, I am (trying), this in perl.

my $sql = "INSERT INTO Account ( `AccID` , `User` , `Password` , `Email` , `First_Name` , `Last_Name` , `My_Team_Name` , `League_Name` , `Budget` , `Rider_1_Name` , `Rider_1_Points` , `Rider_2_Name` , `Rider_2_Points` , `Team` , `Team_Points` , `Tyre` , `Tyre_Points` , `First_Retire` , `First_Retire_Points` , `Pole` , `Pole_Points` , `Total_Points` )
NULL , '', '', 'me@mydomain,com', '', '', '', '', '45', '', '0', '', '0', '', '0', '', '0', '', '0', '', '0', '0'


Kid Charming
07-26-2006, 05:11 PM
Have you tried running this directly in a database client to see if the query itself works correctly?

07-26-2006, 06:36 PM
What does: "doesn't seem to do" mean exactly? Do you get an error message or does nothing run?

A small aside, if you are entering numeric data in your table, don't enclose it in quotes. Enclosing it in quotes creates a string out of it, mysql is then forced to change it to numeric data before inserting, thus slowing down your insert.

07-26-2006, 07:20 PM
I can't detect that it does anything so I think nothing runs.

I shall remember not to enclose numerical data in quotes but actually, that code was prppovided by phpMyAdmin :p


07-26-2006, 07:22 PM
Expounding on Kid Charming (http://www.codingforums.com/member.php?u=23316)'s post, print your $sql and copy and paste it in phpmyadmin and see if it runs. Also look up perls version of mysql_error(). Way back when I did perl I vaguely recall using it.

Good luck;

Kid Charming
07-26-2006, 07:35 PM
If the query came from phpmyadmin, I'm going to assume it works (though, as has been pointed out already, phpmyadmin generates crappy queries). So, assuming that, you're problem's probably somewhere on the perl side. That block may not be running at all, you may be sending the query to the db incorrectly, etc. I'd post a larger chunk of code and have a mod move this to the Perl forum.