Home > Backend Development > PHP Tutorial > Knock-PHP with MySQL, JSON, -phpmysqljson_PHP Tutorial

Knock-PHP with MySQL, JSON, -phpmysqljson_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-12 09:03:55
Original
1084 people have browsed it

knock-PHP with MySQL, JSON, -phpmysqljson

hi

Code~

1. php and mysql

5.4 Modify interface

The same interface and program.

Interface article.modify.php

require_once('../connect.php');
//Read old information
$id = $_GET['id'];
$query = mysqli_query($con,"select * from article where id=$id");
$data = mysqli_fetch_assoc($query);
?>




Untitled Document





< /tr>







Backend management system

< a href="article.add.php">Publish article


Manage article

























Modify article
title
< ;input type="text" name="title" id="title" value=""/>
Author
Introduction

Content

Copyright


The key point is the reading of php and the php call of value in html.

Modify program article.modify.handle.php

//Unconditionally write this sentence if it is related to the database
require_once('../connect.php');

//Accept the modified Data (form delivery)
$id = $_POST['id'];
$title = $_POST['title'];
$author = $_POST['author'];
$description = $_POST['description'];
$content = $_POST['content'];
$dateline = time();

//Write sql modification statement and do Determine whether it is successful or not, and jump back to the modification interface
$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('Failed to modify article');window.location.href='article.manage.php ';</script>";
}
?>

5.5 Article Deletion

First do a demand analysis: It is slightly different from the above. Deleting an article does not require an interface, just a delete button to delete it . So there is only one file. The key sql statement is only one sentence

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

aritcle.del.handle.php

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

//Read the id number. Unlike others that pass 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('Failed to delete article');window.location.href='article.manage.php';</script>";
}
?>

5.6 Article Management List

Requirements analysis: A list displays all articles, followed by two buttons, Delete (link to the deleted module in the previous section) and Modify (link to the previous module)

So, you only need one file, just display the module

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