"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.