Author Topic: Database error while inserting..  (Read 2121 times)

pete3

  • Posts: 9
    • View Profile
Database error while inserting..
« on: March 20, 2008, 08:41:18 am »
Having just switched to PHP5 server, I can get test mails sent no prob. but on new e-mail subscription on entering name & e-mail the message "Database error while inserting.." is given.

Any pointers as to what to look at?

Cheers
Pete

pete3

  • Posts: 9
    • View Profile
Database error while inserting..
« Reply #1 on: March 20, 2008, 11:22:33 am »
Follow up:  I asked our web developer who is (in my mind) a coding genius  :lol:  to take a look....

First reply was as follows:

Quote
To be honest the app should have a better error reporting system, just using this:

mysql_query($cmd) or die("Database error while inserting..");

is pretty much useless because it tells is nothing, so I have added:

mail('info@*******.co.uk', '**** **** Gymratz', mysql_error()."\n".mysql_errno()."\n\n".$cmd);


Following which he came back with the following

Quote
The problem is there is an sql query error in the script, the lm_users table has a primary key called id, this needs to be unique, so you can't have duplicate entries for that field. The query in signup.php is as follows:

$cmd = "INSERT INTO $utable VALUES ('null','$uid','$list','$fname','$lname','$email','$user1','$user2','$user3','$user4','$user5','$user6','$user7','$user8','$user9','$user10','$userseq','$userdel','$confirmed','$today','$ipaddr','$refurl','$html','0');";

notice the first field value is 'null', null will convert to 0 when entered into the table, and when running my tests to confirm this the mysql warning is as follows:

mysql> show warnings;
+---------+------+----------------------------------------------------------+
| Level   | Code | Message                                                  |
+---------+------+----------------------------------------------------------+
| Warning | 1366 | Incorrect integer value: 'null' for column 'id' at row 1 |
+---------+------+----------------------------------------------------------+
1 row in set (0.04 sec)

So it really requires an integer (number). I can't possibly see how this ever worked, unless further down the script the id field is changed, which it isn't. Usually you would have the id field created as an 'auto increment' so it increases the field number by 1 on each new entry, so I suspect somewhere along the line when this table was moved to MYSQL5 from MYSQL4 the auto_increment got dropped.

It is still quite sloppy to ram 'null' into a field that requites an integer because it still generates a warning. Anyway, I have modified the table like so:

alter table lm_users change id id  mediumint(9) auto_increment;

to fix what must have been missing during the change over (there is no other rational explanation). It seems to be working now but my own email is running a little behind, so please try the script again and let me know if it is now fixed. I am awaiting the email to opt-in.


Result is his changes did indeed fix the problem and his subscription was added to the database.

The server was changed from a php4 to a php5 server using the "plesk Migrate" utillity (whatever that is)

Hope this helps DW.
Still love ListmailPro
 :lol:
Pete