New message board, faster access to "add, delete, modify, and query" in mysql ". I hope you can learn more about the improvement and share it with me. The database table name is weibo and contains the id (automatically increasing, remember to select auto_increment in phpmyadmin), nickname (alias varchar), dates (dateTime), content (content, text ), hits (int)
-
- Include ("conn. php ");
- Mysql_set_charset ('utf8 ');
- If (! Empty ($ _ POST ['sub']) {
-
- $ Name = $ _ POST ['nickname']; // Convert the obtained field to a variable.
- $ Content = $ _ POST ['content'];
-
- $ SQL = "INSERT INTO 'Weibo '('nickname', 'dates', 'Content') VALUES (' $ name', now (), '$ content ')"; // database statement, corresponding to the database's nickname, dates (display posting time), content
-
- // Execute the mysql statement. if the execution is successful, a message notification is returned.
- If (mysql_query ($ SQL )){
- Echo ("inserted successfully ");
- } Else {// same as failure
- Echo ("insertion failed"). mysql_error ();
- }
- }
-
- ?>
-
-
-
-
- Message page
-
-
-
-
-
-
-
-
- // Set the administrator, password, and data table to connect to the database
- $ Local = 'localhost ';
- $ Dbname = 'root ';
- $ Passwd = '000000 ';
- $ Db = 'Weibo ';
-
- Mysql_connect ($ local, $ dbname, $ passwd) or die ("falie ");
- Mysql_select_db ($ db );
- // Test the connection. if the connection to the database is successful, the output is yes and faile fails.
- // If ($ query ){
- // Echo ("yes ");
- //} Else {
- // Echo "faile ";
- //}
- ?>
- // Delete the page
- Include ("conn. php ");
- // Delete the database statement
- If (! Empty ($ _ GET ['Del ']) {// Use get to GET the del field
- $ Del = $ _ GET ['del']; // Convert the obtained field to a variable.
- $ SQL = "delete from 'Weibo 'where id =' $ del '"; // The mysql statement to be deleted. delete from table name, with the condition that id is equal to from index. 'del' obtained in php'
- $ Query = mysql_query ($ SQL );
- If ($ query) {// determines whether the mysql statement is successfully executed and the prompt is displayed.
- Echo ("deleted successfully ");
- Header ("refresh: 5; url = 'index. php '");
- } Else {
- Echo ("failed..."). mysql_error ();
- }
-
- }
- ?>
-
- Include ("conn. php ");
- If (! Empty ($ _ GET ['id']) {// if the obtained id is not empty, run the following statement.
- $ SQL = "select * from weibo where id = '". $ _ GET ['id']. "'";
- $ Query = mysql_query ($ SQL );
- $ Rs = mysql_fetch_array ($ query );
- }
-
- If (! Empty ($ _ POST ['sub']) {// if the sub obtained from the form is not empty, run the following statement
-
- $ Name = $ _ POST ['nickname']; // Convert the obtained field to a variable.
- $ Content = $ _ POST ['content'];
- $ Hid = $ _ POST ['hid '];
- $ Mysql = "UPDATE 'Weibo 'SET 'nickname' =' $ name', 'content' = '$ content' where id =' $ hid '";
-
- If (mysql_query ($ mysql )){
- Echo ("inserted successfully ");
- Header ("refresh: 3; url = index. php ");
- } Else {
- Echo ("insertion failed"). mysql_error ();
- }
- }
-
- ?>
-
- Message page
-
-
-
- Message content
-
- Include ("conn. php ");
- Mysql_set_charset ("utf8 ");
- $ SQL = "select * from 'Weibo "';
- $ Query = mysql_query ($ SQL );
-
- While ($ rs = mysql_fetch_array ($ query )){
-
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
"> User name: |
"> Delete"> Edit |
Date: |
|
Content: |
|
- }
- ?>
-
- Include ("conn. php"); // connect to the database
- If (! Empty ($ _ GET ['id']) {// obtain the id in the index, use get
- $ SQL = "select * from weibo where id = '". $ _ GET ['id']. "'"; // execute the database statement, and select weibo as the database, with the condition that id is equal to the slave index. id obtained in php
- $ Query = mysql_query ($ SQL );
- $ Rs = mysql_fetch_array ($ query); // read the table in the database, in the form of an array.
- // The following is a database statement of clicks. the hits is added to the table, and the hits is equal to + 1 each time you browse.
- $ Sqlhits = "update weibo set hits = hits + 1 where id = '". $ _ GET ['id']. "'";
- Mysql_query ($ sqlhits );
- }
- ?>
-
- User name:
- Posting time:
- Clicks:
-
- Content:
|