-PHP and MySQL, JSON, and-phpmysqljson_PHP tutorial

Source: Internet
Author: User
-PHP and MySQL, JSON, and-phpmysqljson. -PHP and MySQL, JSON, and-phpmysqljsonhi ~ 1. the php and mysql5.4 interfaces are also interfaces and programs. Interface article. modify. php? Phprequire_once (... connect. php); read-PHP and MySQL, JSON,-phpmysqljson

Hi

Coding ~

1. php and mysql

5.4 modify interface

The same interface and program.

Interface article. modify. php

Require_once ('../connect. php ');
// Read the old information
$ Id = $ _ GET ['id'];
$ Query = mysqli_query ($ con, "select * from article where id = $ id ");
$ Data = mysqli_fetch_assoc ($ query );
?>




Untitled Document













Background management system

Publish an article


Manage articles

Copyright


The key point is php reading and php calling of values in html.

Modify program article. modify. handle. php

// If it is related to the database, write such a sentence unconditionally
Require_once ('../connect. php ');

// Accept the modified data (Form transfer)
$ Id = $ _ POST ['id'];
$ Title = $ _ POST ['title'];
$ Author = $ _ POST ['author'];
$ Description = $ _ POST ['description'];
$ Content = $ _ POST ['content'];
$ Dateline = time ();

// Write the SQL modification statement, determine whether the statement is successful, and switch back to the modification page.
$ Updatesql = "update article set title = '$ title', author =' $ author', description = '$ description', content =' $ content ', dateline = $ dateline where id = $ id ";
If (mysqli_query ($ con, $ updatesql )){
Echo "script" alert ('Article modified successfully'); window. location. href = 'article. manage. php'; script ";
} Else {
Echo "script" alert ('document modification failed'); window. location. href = 'article. manage. php'; script ";
}
?>

5.5 delete an article

Requirement analysis first: the requirements are slightly different from those above,Deleting an article requires no interface. you only need a delete button to delete it.. So there is only one file. The key SQL statement has only one sentence.

$ Delsql = "delete from article where id = $ id ";

Aritcle. del. handle. php

Require_once ('../connect. php ');

// Read the ID. Unlike others, there are passed values.
$ Id = $ _ GET ['id'];
$ Deletesql = "delete from article where id = $ id ";
If (mysql_query ($ deletesql )){
Echo "script" alert ('Article deleted successfully'); window. location. href = 'article. manage. php'; script ";
} Else {
Echo "script" alert ('document deletion failed'); window. location. href = 'article. manage. php'; script ";
}
?>

5.6 article Management list

Requirement Analysis: The list shows all the articles, followed by two buttons, delete (link to the delete Module in the previous section) and modify (link to the previous module)

Therefore, only one file is needed, and the display module is good.

Article. manage. php

Require_once ('../connect. php ');
$ SQL = "select * from article order by dateline desc ";
$ Query = mysqli_query ($ con, $ SQL );
If ($ query & mysqli_num_rows ($ query )){
While ($ row = mysqli_fetch_assoc ($ query )){
$ Data [] = $ row;
}
} Else {
$ Data = array ();
}

?>




Untitled Document













Background management system

Publish an article


Manage articles


















If (! Empty ($ data )){Foreach ($ data as $ value ){?>
Article Management list
No. Title Operation
    "> Delete"> Modify
Copyright


5.7 Function Summary

Mysqli_connect ()

Mysqli_select_db ()

Mysqli_query ()

Mysqli_error ()

Mysqli_fetch_assoc ()

Mysqli_num_rows ()

VI. Development of the foreground Management Interface

6.1 Article list

Article. list. php

Require_once ('connect. php ');
$ SQL = "select * from article order by dateline desc ";
$ Query = mysqli_query ($ con, $ SQL );
If ($ query & mysqli_num_rows ($ query )){
While ($ row = mysqli_fetch_assoc ($ query )){
$ Data [] = $ row;
}
}
?>




Article publishing system









Php and mysql




  • Article

  • About Us

  • Contact us









If (empty ($ data )){
Echo "there are no articles currently. ask the administrator to add articles in the background ";
} Else {
Foreach ($ data as $ value ){
?>


Array (Size = 2)0 =>

String

 'username' (length=8)  1 => 

String

 'age' (length=3)
["Username", "age"]

A: 2: {I: 0; s: 8: "username"; I: 1; s: 3: "age ";}

-- Common JSON Functions

Json_encode () -- JSON encryption

Json_decode () -- decrypt

1.3 JSON instance description

Hi, knock on the code ~ 1. the interface for modifying php and mysql 5.4 is the same as the interface and program. Interface article. modify. php? Php require_once ('../connect. php'); // read...

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.