Article Release System learning Record

Source: Internet
Author: User

Learning from MU-class network

1, configuration basic commonly used information: config.php:

Header ("content-type:text/html; Charset=utf-8 "); Define (' HOST ', ' 127.0.0.1 '); Define (' USERNAME ', ' Root '); Define (' PASSWORD ', ' PASSWORD ');

2. Connection database: connect.php

Require_once (' config.php ');//LINK database if (!) ( $con =mysql_connect (Host,username,password)) {    echo mysql_error ();} Select the database if (!mysql_select_db (' test ')) {    echo mysql_error;} Character Set if (!mysql_query (' Set names UTF8 ')) {    echo mysql_error ();}

3, add the article, through the form form to submit data to the processing page processing. Processing page:


VALUES (' $title ', ' $author ', ' $description ', ' $content ', $datetime) ';

Put the post information passed over to the storage, assign to the variable. Spelling the SQL statement, use the mysql_query () function to perform the insert operation.

4. List of articles

<?PHPrequire_once(‘.. /connect.php ');$sql= "SELECT * from article ORDER by dateline Desc";$query=mysql_query($sql);if($query&&mysql_num_rows($query)){     while($row=Mysql_fetch_assoc($query)) {        $data[] =$row; }}Else{    $data[] =Array();}?>

Querying the database, the resource identifier exists in the variable query. Assign the data to the array data[] using the MYSQL_FETCH_ASSOC () function. The data is then enumerated in HTML using the Foreach function.

<?PHPif(!Empty($data)){        foreach($data  as $value){            ?> <tr> <td><?phpEcho $value[' ID ']?></td> <td><?phpEcho $value[' title ']?></td> <td><a href= ' article.del.handle.php?id=<?php Echo$value[' id ']?> ' > Delete </a> <a href= ' article.modify.php?id=<?php Echo$value[' id ']?> ' > Modify </a></td> </tr> <?php}} ?>

You need to pass in the ID value of the current article in the Modify and delete link.

5. Revise the article
<? PHP require_once (‘.. /connect.php '); $id $_get [' ID ']; $query mysql_query ("SELECT * from article WHERE id=$id"); $data Mysql_fetch_assoc ($query);? >

Get the ID value of the current article by $_get[' ID ') and read the corresponding data by specifying the ID. And then show it.

6. Delete articles

<? PHP require_once (‘.. /connect.php '); $id $_get [' ID ']; $deletesql $id"; if (mysql_query($deletesql)) {    echo "<script>alert (' article deletion succeeded ') </script> ";} Else {    echo "<script>alert (' article deletion failed ') </script>";}

PS: Small Error

The "1" id forgot to set it to auto-grow. You cannot add records after inserting a record.
"2" Spelling error
"3" less echo.
"4" forgot the single quotation mark or double quotation mark "" "" "" $ and other symbols.
The introduction of PHP code in "5" HTML requires a closed <?php?>
"6" $_post[' ID '] $_get[' ID '], uppercase, [], ',

Article Release System learning Record

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.