1, starting from the database, first set up test data, the MySQL used here, through the script mode to create test data.
SET NAMES utf8;drop DATABASE IF EXISTS disk; CREATE DATABASE disk Charset=utf8; Use disk; CREATE TABLE udisk (uid INT PRIMARY KEY auto_increment,uname varchar), pic VARCHAR, Price FLOAT (9,2), Addedtime BIGINT); INSERT into Udisk VALUES (null, ' Kingston se9h ', ' img/1.jpg ', ' 49.90 ', ' 1234567890123 '), (null, ' Kingston Dt100g3 ', ' IMG/2. JPG ', ' 47.90 ', ' 1234567890123 '), (null, ' Right still transshow ', ' img/3.jpg ', ' 39.90 ', ' 1234567890123 '), (null, ' SanDisk (SanDisk) Cool treatments ( CZ73) ', ' img/4.jpg ', ' 79.90 ', ' 1234567890123 '), (NULL, ' Kingston 32GB ', ' img/5.jpg ', ' 99.90 ', ' 1234567890123 ');
2, create init.php is mainly used to save the PHP connection database related code.
<?php/* Database Link Initialization page */$conn = mysqli_connect (' 127.0.0.1 ', ' root ', ' ', ' Tarena ', 3306); $sql = ' SET NAMES UTF8 '; mysqli_ Query ($conn, $sql);
3, set up add.php implement PHP operation database to add data function.
<?php@ $uname = $_request[' uname ') or Die (' uname required '), @ $pic = $_request[' pic ') or Die (' pic required '); @ $price = $_ request[' price ' or die (' price required '), require (' disk_inti.php '); $addTime = time () *1000; $sql = "INSERT into Udisk VALUES (NULL, ' $uname ', ' $pic ', ' $price ', ' $addTime ') '; $result = Mysqli_query ($conn, $sql); if ($result ===false) {echo " Add failed, please check the SQL statement ";} Else{echo "added successfully, product number is". mysqli_insert_id ($conn); echo "<a href= ' udisk_select.php ' > view so USB stick </a>";}
4, create a view (add.html file) to implement the added functionality a simple data add entry test.
<!doctype html>
5. Use PHP to create the data lookup function main interface and use JS binding delete function
<?php//Execute SQL Lookup statement require (' disk_inti.php '); $sql = "SELECT * from Udisk"; $result = Mysqli_query ($conn, $sql); if ($resu Lt===false) {//Find results echo "Data query failed, please check SQL statement";} else{$list = Mysqli_fetch_all ($result, 1);} Var_dump ($list);? ><!doctype html>
6, create delete.php complete Delete function
<?php@ $uid = $_request[' uid ') or Die (' uid required '), require (' disk_inti.php '); $sql = "DELETE from Udisk WHERE uid= $uid "; $result = Mysqli_query ($conn, $sql), if ($result ===false) {echo" Delete failed ";} Else{echo "
Use PHP to perform simple curd operations with SQL