[Do not translate] make a simple message board function, but the database cannot add data

Source: Internet
Author: User
Tags how to use sql
[Advice] 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: 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'


Reply to discussion (solution)

Mysql_query ($ SQL) or die (mysql_error (); // The error message returned.

Do not add @ to block errors

I tried to display it.

Mysql_query ($ SQL) or die (mysql_error (); // The error message returned.
It seems that I understand
Error -- Column 'id' cannot be null
Is it null when I insert the id value?
However, when assigning values to IDs in the video (php 2013 ),
Can I leave no value in the past, but do I have a placeholder? Null

Your id is not a primary key. it automatically increases.

When the id is automatically increased by the primary key, it can be left blank or placeholder. it can be replaced by null or.

Your id is not a primary key. it automatically increases.
I did not set id as the primary key
However, when watching his video in the database, there is an underline under the id. isn't that the primary key?
I think the primary key behind the id in the news table is yellow, while the primary key behind the contents is gray.
Changing null to ''is normal... (isn't it true that the new version does not support this? must we use null in a standardized manner ?)

..

..
Do you have QQ? Why can't I upload images to the forum?
I used ''to find that the data is added, but the id field in the table is displayed as 0, not automatically increasing.

Change your id to the primary key and automatically increase.

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.

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.

Change your id to the primary key and automatically increase.
Thank you. I changed it ~ When adding a field, you can select a A_ I option.
I didn't know what this was before, but Baidu just clicked it.
In other words, I need to have a simple graduation project for volunteer information management.
How should I create a database?
In the past, foreign teachers taught us how to use SQL SEVER2008 with a view. what primary key foreign keys can we choose?
However, I did not see the graphical function in phpmyadmin.

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.
No error. it is null.
New version changed

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.