For help, a problem that plagued me for one day and one night, so that I could not eat or drink water. recently I learned php and encountered a problem. My php and mysql databases are connected, that is, the data cannot be written into the mysql database. the following database name: bbs table name message Field & nbsp; idtinyint (1) auto_incrementpr for help. one of the reasons has plagued me one day and one night, I cannot eat or drink water.
I recently learned php and encountered a problem.
My php and mysql databases are connected, that is, data cannot be written into the mysql database.
The database is as follows:
Database name bbs
Table name message
Field
Id tinyint (1) auto_increment primary key
User varchar (25)
Title varchar (50)
Content tinytext
Lastdate date
Thanks to the two php files
File 1 conn. php
[Email protected] _ connect ("localhost", "root", "") or die ("database connection error ");
Mysql_select_db ("bbs", $ conn );
Mysql_query ("set names 'gbk'"); // use Chinese encoding
?>
File 2 add. php
Include ("conn. php ");
If ($ _ post ['submit ']) {
$ SQL = "insert into message (id, user, title, content, lastdate )".
"Values ('', '$ _ post [user]', '$ _ post [title]', '$ _ post [content]', 'Now ()') ";
Mysql_query ($ SQL) or die (mysql_error (); // An error is reported at any time.
Echo "published successfully ";
}
?>
In this case, the database connection does not report an error, that is, inputting data in the form does not add data to the database, and you do not know what went wrong. please give some advice. thank you ~
------ Solution --------------------
If ($ _ post ['submit ']) {
Change
If ($ _ POST ['submit ']) {
Modify the SQL statement in similar places.
------ Solution --------------------
It is very likely that your SQL statement has a problem. let's take a look at it ~~
------ Solution --------------------
$ _ Post cannot be in lower case. $ _ POST must be in upper case.
------ Solution --------------------
Not $ _ pos is $ _ POST
------ Solution --------------------
If you encounter problems in the future, please come up and ask them in time. This problem is not worth so long. Learning to debug is of great help to learning.
If php does not prompt an error (the error prompt is opened), it is certain that some of the executed syntax should be normal. Then add the output variable/array exit () according to the code execution steps.
For example, your problem is added in add. php.
Print_r ($ _ post [xxxx]) // follow your incorrect syntax
If an error is prompted, start from this point.
Why is an error in the $ _ post array.
The last reminder is that the php error prompt must be enabled during learning/debugging.
------ Solution --------------------
Some things are well defined, and there is no reason for this.
------ Solution --------------------
Discussion
Thank you! the first time I came to csdn, I felt very strange. I thought no one was asking me. I went downstairs and bought something. I answered so many questions when I came back. thank you.
I didn't learn computer science. php gave me the feeling of being like Tianshu. I should not say I want to learn to write code first, that is, configuring php on my own machine will make me unable to do anything, finally, the environment configuration is ready and the code can be run. Then I encountered this problem today ~
The problem has finally been solved. if it cannot be solved, I am not actually going to play with PHP, because I have listened to the video courses on the internet and I have spent a lot of time ......