Why does my php insert two identical data records to mysql at a time?

Source: Internet
Author: User
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 ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.