The new person's message board, faster contact MySQL in the "adding and deleting". Seeking guidance, there are many shortcomings, I hope that we learn more in the process of improvement, to share. The table name of the database is Weibo, which contains the ID (auto-Grow remember to select Auto_increment in phpMyAdmin), nickname (alias varchar), dates (dateTime), content (contents, text), Hits (int)
-
- Include ("conn.php");
- Mysql_set_charset (' UTF8 ');
- if (!empty ($_post[' Sub ')) {
- $name = $_post[' nickname '); The obtained field is converted to a variable
- $content = $_post[' content '];
- $sql = "INSERT into ' Weibo ' (' nickname ', ' dates ', ' content ') VALUES (' $name ', now (), ' $content ')"; Database statements, corresponding to the nickname,dates in the database (showing the publication time), content
- Executes the MySQL statement and returns a message notification if execution succeeds.
- if (mysql_query ($sql)) {
- Echo ("Insert succeeded");
- }else {//fail similarly
- Echo ("Insert Failed"). Mysql_error ();
- }
- }
- ?>
-
- Message page
Copy Code
- Set up administrator, password, and connected data tables to connect to the database
- $local = ' localhost ';
- $dbname = ' root ';
- $passwd = ' 3363064 ';
- $db = ' Weibo ';
- Mysql_connect ($local, $dbname, $passwd) or Die ("Falie");
- mysql_select_db ($DB);
- Test connection, if connection database is successful, output Yes, fail Faile
- if ($query) {
- Echo ("yes");
- }else {
- echo "Faile";
- // }
- ?>
Copy Code
- Delete Page
- Include ("conn.php");
- Delete a database sentence
- if (!empty ($_get[' del '))) {//Use Get to Get del field
- $del = $_get[' del ']; Convert the obtained field to a variable
- $sql = "Delete from ' Weibo ' where id= ' $del '"; Deleted MySQL statement, delete from table name, conditional ID equals ' del ' obtained from index.php
- $query =mysql_query ($sql);
- if ($query) {//determines if the MySQL statement is executed successfully and prompts.
- Echo ("delete succeeded");
- Header ("Refresh:5;url= ' index.php '");
- }else {
- Echo ("Failed ..."). Mysql_error ();
- }
- }
- ?>
Copy Code
-
- Include ("conn.php");
- if (!empty ($_get[' id '))) {//If the obtained ID is not empty, start executing 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, execute the following statement
- $name = $_post[' nickname '); The obtained field is converted 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 ("Insert succeeded");
- Header ("refresh:3;url=index.php");
- }else {
- Echo ("Insert Failed"). Mysql_error ();
- }
- }
- ?>
-
- Message page
Copy Code
- message content
- !--? php
- include ("conn.php");
- mysql_set_charset ("UTF8");
- $sql = "SELECT * from ' Weibo '";
- $query = mysql_query ($sql);
-
- while ($rs = Mysql_fetch_array ($query)) {
-
- ?
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
> Username: |
!--? php echo ($rs [' nickname ']);?--> > Delete > Edit |
Date: |
!--? php echo ($rs [' dates '),?-- |
contents: |
!--? PHP EC Ho ($rs [' content ');?--" |
- "!--? php }
- ";
Copy Code
-
- Include ("conn.php"); Connecting to a database
- if (!empty ($_get[' id ')) {//Get ID in index, use get
- $sql = "Select *from Weibo where id = '". $_get[' id ']. "'"; Execute the database statement and select the database as Weibo, provided the ID equals the ID obtained from index.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 click-through database statement that adds hits to the table, and hits equals +1 per browse.
- $sqlhits = "Update Weibo set hits=hits+1 where id = '". $_get[' id ']. "'";
- mysql_query ($sqlhits);
- }
- ?>
-
User name:
Release Date:
Number of Hits:
-
- Content:
Copy Code |