MySql 4.1.15 & 5.0 PHP 4.4.4 & 5.1.6
I have a simple self-contained form (posting to itself). When I insert a new record in the database, it is saving it twice.
I have set up the same database from scratch on two different servers with two different versions of MySQL, and had the same results. I have written this code several different ways, as well as separating the HTML and the PHP processing into two separate files, all still with the same results. I have taken the code down to bare bones (4 fields with no validation, etc.) and I still have the same results.
This doesn't seem to be a known bug, and with several web searches on the subject, I have run into only a few other people with the same problem. So far, no resolves.
Here is the code in a nut shell:
Your Data Has Been Saved
'); clear($_POST); } else { echo('I have a simple self-contained form (posting to itself). When I insert a new record in the database, it is saving it twice.
I have set up the same database from scratch on two different servers with two different versions of MySQL, and had the same results. I have written this code several different ways, as well as separating the HTML and the PHP processing into two separate files, all still with the same results. I have taken the code down to bare bones (4 fields with no validation, etc.) and I still have the same results.
This doesn't seem to be a known bug, and with several web searches on the subject, I have run into only a few other people with the same problem. So far, no resolves.
Here is the code in a nut shell:
Your Data Has Been Saved
There was an error in processing the data
'); } } } else // nothing has been submitted yet { set variables for form } }?> Print top of page Print any error messages if fields did not validate ?> Another way I have done this with the same results:
mysql_select_db($DBName) or die ('Unable to select database!'); $xQuery = "INSERT INTO CheckList set NameFirst = '$NameFirst', NameMid = '$NameMid', NameLast = '$NameLast', Position = '$Position'"; $SaveIt = mysql_query($xQuery); if(!$SaveIt) { echo('
There was an error in processing the data
'); } else { echo(' Your Data Has Been Saved
'); clear($_POST); }I'm really puzzled - especially since I have similar forms that work fine. I'm no PHP/MySQL guru, by any means. I have spent hours working on this code, and have pretty much come to conclusion that the error is not in the code - there must be something in how I set up the database.
The structure of the database is:
http://www.filerabbit.com/images/structure.jpg
With the following indexes:
http://www.filerabbit.com/images/structure2.jpg
Comment