[Guidance] makes a simple message board function, but the database cannot add data
Source: Internet
Author: User
[Tips] make a simple message board function, but the database cannot add the data environment: Win7 (x64), Wamp integration (PHP5.4.3 + MySQL5.5.24 + Apache2.4.2 + PHPMyAdmin3.5.1) objective: as a simple message board function, you can click "post" to add a related [ask for advice] to the database for a simple message board function, but the database cannot add data.
Environment: Win7 (x64) and Wamp integration (PHP5.4.3 + mysql5.24 + Apache2.4.2 + PHPMyAdmin3.5.1)
Objective: to create a simple message board function, click "Publish" to add a piece of relevant data to the database.
Question: After you press "post", "insert successful" is displayed ". But it is not added to 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 '");
?>
******************
------------------------------ Add. php --------------------------------------
Include ("conn. php"); // introduce the 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 "inserted successfully! ";
}
?>
******************
----------------------------- Database -------------------------------------
Database name: db_php100_microblog
Table name: news
Field name: 'id', 'title', 'dates', 'Contents'
------ Solution --------------------
Mysql_query ($ SQL) or die (mysql_error (); // The error message returned.
------ Solution --------------------
When the id is automatically increased by the primary key, it can be left blank or placeholder. it can be replaced by null or.
------ Solution --------------------
The database ID is set to the primary key (with the key displayed), and the attribute is always set to auto-increment. when inserting data, do not assign a value to it.
------ Solution --------------------
The database cannot insert data, but the subsequent code can run. it must be an SQL error. Check whether the types of each field match. Why should I set the id to null? it must be wrong here.
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