A problem that troubles me one day and one night, so that I can't eat or drink any water.-php Tutorial

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

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.