Yesterday, the approximate function of the message book has been obtained '~~~ Today, we will slightly improve the addition of an administrator's message management function ~~~ $ _ Session [item] is mainly used here ~~ '& Nbsp; okay '~ 'First, I changed the feature of yesterday and then added it ~~~ & Nbsp; first, we will display a message at the same time on the home page, as well as the message adding box ~~ This makes it easier for the message holder '~ '& Nbsp; no more '~ Paste the code. yesterday, the approximate function of the message book was obtained '~~~ Today, we will slightly improve the addition of an administrator's message management function ~~~ It is mainly used here
$ _ Session ['item'] this stuff ~~ '
Okay '~ 'First, I changed the feature of yesterday and then added it ~~~
First, we will display a message on the home page and add a message box ~~ This makes it easier for the message holder '~ '
Not much '~ Paste the code out:
Index. php
Message book
Message Management
$ Conn = MySQL_connect ("localhost: 6033", "root", ""); // open the MySQL server connection
Mysql_select_db ("guest_book"); // link to the database
Mysql_query ("set names GB2312"); // solves Chinese garbled characters
$ Exec = "select * from contents"; // SQL statement
$ Result = mysql_query ($ exec); // execute the SQL statement and return the result
While ($ rs = mysql_fetch_object ($ result ))
{
Echo"
Name: ". $ rs-> name ." |
";Echo"
Message: ". $ rs-> content ." |
";
Echo "...................................... ........................................ ........................................ ....... ";
}
Mysql_close ();
?>
Add a header ("location: index. php") to the updata. php page. redirect the statement to the homepage '~~
Updata. php
$ Name = $ _ POST ['User _ name'];
$ Content = $ _ POST ['post _ contents'];
$ Conn = mysql_connect ("localhost: 6033", "root ","");
Mysql_query ("set names GB2312"); // solves Chinese garbled characters
Mysql_select_db ("guest_book ");
$ Exec = "insert into contents (name, content) values ('". $ _ POST ['User _ name']. "','". $ _ POST ['post _ contents']. "')";
$ Result = mysql_query ($ exec );
Mysql_close ();
Header ("location: index. php ");
?>
HOHO ~~~ Is that the case '~~
Okay '~ Next we will add a new management function ~~ This message book is even more powerful '~
The message management module is divided into the administrator login page admin_login.htm, administrator verification page admin_check.php background management homepage admin_index.php
Xiannong's webpage admin_login.htm
This is much simpler, so I will not talk about it anymore '~~
Admin_check.php administrator verification
Session_start ();
$ Admin_name = $ _ POST ['admin _ name'];
$ Admin_password = $ _ POST ['admin _ password'];
$ Conn = mysql_connect ("localhost: 6033", "root ","");
Mysql_select_db ("guest_book ");
$ Exec = "select * from admin where admin_name = '". $ admin_name ."'";
$ Result = mysql_query ($ exec );
If ($ rs = mysql_fetch_object ($ result ))
{If ($ rs-> admin_password = $ admin_password)
{$ _ SESSION ['admin'] = "OK ";
Header ("location: admin_index.php ");
}
Else echo "incorrect password ";
}
Else echo "incorrect user name ";
Mysql_close ();
?>
Here the most important thing is session ~~~ Session is used in all things. add session_start () at the beginning of the page; otherwise, the session will not be available ~~ So what is session? Because the webpage transmission method (that is, http) is not a permanent connection ~~ 'The server cannot transmit the variable between two different pages '~~ Alas. I cannot make it clear at once '~~ Or look at the http://www.chinalinuxpub.com/read.php here? Wid = 87
The above is a detailed description. it is used to verify the administrator's identity '~~
Now let's talk about admin_index.php on the background management homepage.
Session_start ();
If ($ _ SESSION ['admin'] = "OK ")
{
$ Conn = mysql_connect ("localhost: 6033", "root ","");
Mysql_select_db ("guest_book ");
$ Exec = "select * from contents ";
$ Result = mysql_query ($ exec );
While ($ rs = mysql_fetch_object ($ result ))
{
Echo"
Name: ". $ rs-> name ." |
";Echo"
Message: ". $ rs-> content ." |
";
Echo "id."> modify id. "> delete ";
}
Echo"
Home page ";
}
Mysql_close ();
?>
Here the most important sentence is echo "id."> modify id. "> delete ";
Used to pass parameters to the connected address ~~ Let's take a look at the following to find out what's useful.
Modify. php
Session_start ();
If ($ _ SESSION ['admin'] = "OK ")
{
$ Conn = mysql_connect ("localhost: 6033", "root ","");
Mysql_select_db ("guest_book ");
$ Exec = "select * from contents where id = ". $ _ GET ['id'];/* here, $ _ GET ['id'] is used to pull the parameter passed from that connection */
$ Result = mysql_query ($ exec );
$ Rs = mysql_fetch_object ($ result );
$ Name = $ rs-> name;
$ Content = $ rs-> content;
$ Id = $ rs-> id;
?>
}
Mysql_close ();
?>
Here this Echo $ id
Let's look at the final data modification implementation page modify2.php
Session_start ();
If ($ _ SESSION ['admin'] = "OK ")
{
$ Conn = mysql_connect ("localhost: 6033", "root ","");
Mysql_select_db ("guest_book ");
$ Exec = "select * from contents where id =". $ _ GET ['id'];
$ Exec = "update contents set content = '". $ _ POST ['post _ contents']. "'Where id =". $ _ post ['id'];
$ Result = mysql_query ($ exec );
}
Mysql_close ();
Header ("location: admin_index.php ");
?>
Finally, the deletion function is implemented.
Delete. php
Session_start ();
If ($ _ SESSION ['admin'] = "OK ")
{
$ Conn = mysql_connect ("localhost: 6033", "root ","");
Mysql_select_db ("guest_book ");
$ Exec = "delete from contents where id =". $ _ GET ['id'];
Mysql_query ($ exec );
Mysql_close ();
Header ("location: admin_index.php ");
}
?>
//////////////////////////////////////// //////////////////////////////////////// /////////////////////////////////
The knowledge used today is as follows:
1: session_start (); $ _ SESSION ['variable name'] = $ variable name or a specific value
2: aaa uses this method to pass the parameter and uses $ _ GET ['var'] to receive the passed value.
3: Data modification: $ exec = "update tablename set item1 = '". $ _ POST ['item1']. "'Where ...";
4: data deletion: $ exec = "delete from tablename where ...";
////////////////////////////////////////
Does it look messy ~~~~ Use include and requre tomorrow to modify it '~~~~ Make the program look clear ~~~
This is today.