First create a database db_0808, and import the table student in db_0808 into the web page.
CURD.php
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Title</title> </head> <body> <?php $db = new Mysqli("localhost","root","root","db_0808"); //!$db?"":die("链接错误"); empty(mysqli_connect_error())?"":die("链接错误"); $sql = "select * from student where is_delete='0'"; //$data = $db->query($sql)->fetch_all();//索引数组形式的所有数据 ?> <table border="1"> <tr> <td>id</td> <td>名字</td> <td>性别</td> <td>班级</td> <td>生日</td> <td>操作</td> </tr> <?php $result=$db->query($sql); while ($data=$result->fetch_row()){ //索引数组形式的第一条数据 // foreach ($data as $i){ if ($data[2]==1){ $data[2]="男"; }else if ($data[2]==0){ $data[2]="女"; }else{ $data[2]="保密"; } echo "<tr> <td>{$data[0]}</td> <td>{$data[1]}</td> <td>{$data[2]}</td> <td>{$data[3]}</td> <td>{$data[4]}</td> <td><a href='delete.php?id={$data[0]}'>删除</a> <a href='xiugai.php?id={$data[0]}'>修改</a> </td> </tr>"; } ?> </table> <a href="add.php">新增用户</a> </body> </html>
Add new information to the database add.php
##
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form method="post" action="addpost.php"> <input type="text" name="name" placeholder="姓名"> <input type="radio" name="sex" value="1" id="man"><label for="man">男</label> <input type="radio" name="sex" value="0" id="nv"><label for="nv">女</label> <input type="text" name="banji" placeholder="班级"> <!-- <input type="text" name="age" placeholder="年龄">--> <input type="text" name="birthday" placeholder="出生年月"> <input type="submit" value="提交"> </form> </body> </html>Process add.php information addpost.php
<?php /** * Created by fcc * User: Administrator * Date: 2017/10/13 * Time: 15:49 */$name = $_POST['name'];// var_dump($name); $sex = $_POST['sex']; $ban=$_POST['banji'];// $age = $_POST['age']; $birthday = $_POST['birthday']; $db=new Mysqli("localhost","root","root","db_0808"); $sql = "INSERT INTO student VALUES (null,'{$name}',{$sex},{$ban},'{$birthday}',DEFAULT,null)"; if ($db->query($sql)){header("location:CURD.php"); }else{ header("location:add.php"); }Add information successfullyDelete information delete.php
<?php/** * Created by fcc * User: Administrator * Date: 2017/10/14 * Time: 10:56 */$id=$_GET['id'];$db=new Mysqli("localhost","root","root","db_0808");empty(mysqli_connect_error())?"":die("链接错误");//$sql="DELETE FROM student WHERE Sno='{$id}'";//彻底删除,数据库中内容删除$sql = "update student set is_delete = '1' where Sno= '{$id}'";//表面删除,数据库中内容仍存在if ($db->query($sql)){ header("location:CURD.php"); };Change information page xiugai.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <?php $s = null;if(isset($_GET['id'])){ $id = $_GET['id']; $db=new Mysqli("localhost","root","root","db_0808"); empty(Mysqli_connect_error())?"":die("连接错误"); $sql="select * from student where Sno='{$id}'"; $r=$db->query($sql);//var_dump($r); $s=$r->fetch_row(); }?> <form method="post" action="xiugaichuli.php"> <input type="hidden" name="id" value="<?php echo $s[0]?>"> <input type="text" name="name" placeholder="<?php echo $s[1]?>"> <input type="radio" name="sex" value="0" <?php echo $s[2]?"":"checked='checked'"; ?> id="nv"><label for="nv">女</label> <input type="radio" name="sex" value="1" <?php echo $s[2]?"checked='checked'":""; ?> id="nan"><label for="nan">男</label> <input type="text" name="banji" placeholder="<?php echo $s[3]?>"> <!-- <input type="text" name="age" placeholder="年龄">--> <input type="text" name="birthday" placeholder="<?php echo $s[4]?>"> <input type="submit" value="提交"> </form> </body> </html>Change information processing page xiugaichuli.php
<?php /** * Created by fcc * User: Administrator * Date: 2017/10/17 * Time: 9:07 */ $id=$_POST['id']; $name=$_POST['name']; $sex=$_POST['sex']; $banji=$_POST['banji']; $birthday=$_POST['birthday']; $db=new Mysqli("localhost","root","root","db_0808"); empty(Mysqli_connect_error())?"":"连接错误"; $sql="UPDATE student SET Sname='{$name}',Ssex='{$sex}',class='{$banji}',birthday='{$birthday}'WHERE Sno='{$id}'"; //var_dump($sql); if ($db->query($sql)){ header("location:CURD.php"); }
The above is the detailed content of PHP database addition, deletion, modification and query methods. For more information, please follow other related articles on the PHP Chinese website!

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor
