Why does my php insert two identical data records to mysql at a time? each time I submit the data, two identical information records are inserted in the database. My primary key id is set to auto-increment, and the problem seems to be here. when I insert the id value on the php page, click Submit. at this time, mysql just inserts a message. This Cainiao has just learned php, and I can't explain it! Hope all the heroes pass by can help you! Why does my php insert two identical data records to mysql at a time?
Each time I submit a request, the database inserts two identical information. My primary key id is set to auto-increment, and the problem seems to be here. when I insert the id value on the php page, click Submit. at this time, mysql just inserts a message.
This Cainiao has just learned php, and I can't explain it!
Hope all the heroes pass by can help you! Thank you!
If ($ _ POST ['submit ']) {
Mysql_query ("set SQL _mode = ''");
$ SQL = "insert into message1 (id, user, title, content, lastdate) values ('', '$ _ POST [user]', '$ _ POST [title]', '$ _ POST [content]', now ())";
Echo "$ SQL ";
Mysql_query ($ SQL, $ conn) or die ("database link error ");
}
------ Solution --------------------
Refreshed?
------ Solution --------------------
I don't think it is caused by the value of id.
Run the SELECT * FROM message1; command line. what do you get?
It is best to paste the show create table 'message ';
------ Solution --------------------
First try another browser, probably because of the browser;
Then, let's see if your submission is form submission + JS submission? May accidentally submit twice
------ Solution --------------------
No problems found. it is normal. It is estimated that you have submitted it again on the client. check it again.
In addition, how do you determine that there are two identical messages? Because at least no primary key id is repeated.
------ Solution --------------------
PHP code
Mysql_query ($ SQL, $ conn) or die ("database link error");} // if (mysql_query ($ SQL, $ conn) for the second query ))