"Ask for guidance" to do a simple message board function, but the database can not add data

Source: Internet
Author: User
"Ask for guidance" to do a simple message board function, but the database can not add data
Environment: Win7 (x64), Wamp Integration (php5.4.3+mysql5.5.24+apache2.4.2+phpmyadmin3.5.1)
Objective: To make a simple message board function, one click "Publish" can add a related data in the database.
issue: Press "POST" to display "Insert succeeded". But it's not added in the background database.
------------------------------- conn.php------------------------------------
@mysql_connect ("localhost", "root", "root") or Die ("MySQL connection failed");
@mysql_select_db ("Db_php100_microblog") or Die ("DB connection Failed");
mysql_query ("Set names ' GBK '");
?>
Normal operation, no error ******************
------------------------------ add.php--------------------------------------
Include ("conn.php");//Introduction of database
if (!empty ($_post[' Sub ')) {
$title = $_post[' title '];
$con = $_post[' con '];
$sql = "INSERT into ' news ' (' id ', ' title ', ' dates ', ' contents ')
VALUES (null, ' $title ', now (), ' $con ') ";
mysql_query ($sql);
echo "Insert success! ";
}
?>


Normal operation, no error ******************
-----------------------------Database-related-------------------------------------
Database name: Db_php100_microblog
Table Name: News
Field name: ' id ', ' title ', ' dates ', ' contents '


------Solution--------------------
mysql_query ($sql) or Die (Mysql_error ()); What's wrong with that?
------Solution--------------------
When the ID is the primary key autogrow, it can be either unassigned or placeholder, with null or ' ' instead.
------Solution--------------------
The ID of the database is set as the primary key (shown with the key), and the property is always set to autogrow, so you don't have to assign a value when inserting the data
------Solution--------------------
The database can't plug in the data, and then the code can run, it must be SQL write wrong. See if the type of each field matches. Why is the ID set to NULL, it must be wrong here.
  • Related Article

    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.