What's wrong with me? $ SQL & nbsp; INSERT & nbsp; INTO & nbsp; patient & nbsp; (order, name, age, sex, tel, qq, disease, media_from, area, ordertime, teshuyaoqiu, content, ordertag, beizhu, zixun_id) VAL
$ SQL = "INSERT INTO patient (order, name, age, sex, tel, qq, disease, media_from, area, ordertime, teshuyaoqiu, content, ordertag, beizhu, zixun_id) VALUES ('$ order',' $ name', '$ age',' $ tel ',' $ QQ', '$ disease', '$ media_from ', '$ region',' $ ordertime', '$ teshuyaoqiu', '$ content',' $ ordertag ',' $ beizhu', '$ zixun_id ')";
If (mysql_query ($ SQL, $ conn )){
Exit ('added successfully! Click here on the homepage ');
} Else {
Echo 'Sorry! Failed to add data: ', mysql_error (),'
';
Echo 'click here to return retry ';
}
Running result:
Sorry! Failed to add data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order, name, age, sex, tel, qq, disease, media_from, area, ordertime, teshuyaoqiu, content, 'At line 1
Click here to return and try again
------ Solution ----------------------
Order is a reserved mysql word, which should be escaped during other operations
'Order'
------ Solution ----------------------
Two problems
1. order is the keyword. it is best not to use it.
To use it, use.
2. the number of insert fields does not match the number of values.
15 fields, but only 14 values, less sex
Change to this.
$ SQL = "INSERT INTO patient ('order', name, age, sex, tel, qq, disease, media_from, area, ordertime, teshuyaoqiu, content, ordertag, beizhu, zixun_id) VALUES ('$ order',' $ name', '$ age',' $ sex', '$ tel', '$ QQ',' $ disease ', '$ media_from', '$ region',' $ ordertime ',' $ teshuyaoqiu ',' $ content', '$ ordertag', '$ beizhu',' $ zixun_id ') ";