, a troubled little brother I day and night, let younger brother I can't eat, water can't drink the related problems

Source: Internet
Author: User
Help, a troubled me a day and night, let me eat, water can't drink the problem
Recently learned PHP, encountered a problem.
My PHP is connected to the MySQL database, that is, the data is not 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, two php files
Document One conn.php
[Email Protected]_connect ("localhost", "root", "") or Die ("Connection Database error");
mysql_select_db ("BBS", $conn);
mysql_query ("Set names ' GBK '");//Use Chinese encoding
?>
File Two 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 ());//Always Prompt for errors
echo "Publishing Success";
}

?>



File in this way, the database connection is not an error, that is, in the form of input data in the database will not add data, do not know where the problem, but also expert guidance, thank you ~


------Solution--------------------
if ($_post[' submit ']) {

Change to

if ($_post[' submit ']) {

A similar place in the SQL statement is modified.
------Solution--------------------
It may be that your SQL statement is out of the question.
------Solution--------------------
$_post can not be lowercase ah, to $_post to capitalize
------Solution--------------------
Not $_pos is $_post.
------Solution--------------------
After encountering problems in time to ask, this kind of problem is not worth bothering so long time. Learning to debug is a great help to study.

If PHP does not prompt for errors (the error is turned on), then there should be no problem with certain portions of the syntax being executed. Then add the output variable/array exit () separately according to the steps executed by the code. The way you can debug it in one step.

For example, your problem is increasing in add.php.

Print_r ($_post[xxxx])//According to your wrong wording

It's definitely starting to suggest something wrong, so start with this place.

$_post array why the error occurred.

The last reminder to learn/debug when PHP error prompt must be turned on.
------Solution--------------------
Some things are prescribed, and this is not why.
------Solution--------------------
discuss

Thank you, my first time to csdn, feel very strange, thought no one to me, the result went downstairs to buy something, come back so much I answered, thank you.
I am not learning computer, PHP to give me the feeling like the heavenly book, do not say to learn to write code, is in their own machine configuration php all put me out of the way, finally fix the environment configuration, can run the code. And today I met this problem, hehe ~

The problem finally solved, if not solve, I am actually ready to play PHP, because I am listening to the online video of the class, I spent a lot of ...
  • 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.