<meta charset= "UTF-8" >
<?php
$link =mysqli_connect ("localhost:3306", "root", "root", "supermarket");
if (! $link) {
echo "The reason for the connection failure is:". Mysqli_connect_error ();
}
Mysqli_query ($link, "Set names UTF8");
$sql = "SELECT * from goods";
$a =mysqli_query ($link, $sql);
while ($res =mysqli_fetch_assoc ($a)) {
$arr []= $res;
}
Delete
<meta charset= "UTF-8";
<?php
$link =mysqli_connect ("localhost:3306", "root", "root", " Supermarket ");
if (! $link) {
echo "Connection failed because:". Mysqli_connect_error ();
}
Mysqli_query ($link, "Set names UTF8");
$id =isset ($_get[' id '))? Trim ($_get[' id '): ';
if (empty ($id)) Die ("The data to be deleted is not passed over");
$sql = "Delete from goods where goods_id in ($id)";
$a =mysqli_query ($link, $sql);
if ($a) {
echo "delete succeeded";
Header ("location:a.php");
}
else{
echo "Delete failed";
Header ("location:a.php");
}
//Add
<?php
$date =isset ($_post[' date ')? Trim ($_post[' date '): ';
$ge =isset ($_post[' ge ')) trim ($_post[' ge '): ';
$shu =isset ($_post[' shu ') "Trim ($_post[' Shu ']): ';
if (empty ($date)) Die ("Date cannot be empty");
if (empty ($ge)) die ("Price cannot be empty");
if (empty ($shu)) Die ("Quantity cannot be empty");
$link =mysqli_connect ("localhost:3306", "root", "root", "supermarket");
if (! $link) {
echo "The reason for the connection failure is:". Mysqli_connect_error ();
}
Mysqli_query ($link, "Set names UTF8");
$sql = "INSERT into goods (goods_id,goods_date,goods_price,goods_num) VALUES (null, '". $date. "', '". $ge. "', '". $shu. "')";
Change fields according to requirements
$a =mysqli_query ($link, $sql);
if ($a) {
echo "Add success";
Header ("location:xing.html");
}else{
echo "Add failed";
Header ("location:xing.html");
}
?>
Modify
<meta charset= "UTF-8" >
<?php
$link =mysqli_connect ("localhost:3306", "root", "root", "Yuekao");
The IF (! $link) echo "link failed due to:". Mysqli_connect_error ();
Mysqli_query ($link, "Set names UTF8");
$XM =isset ($_post[' XM ']) trim ($_post[' xm '): ';
$q =isset ($_post[' Q ']) trim ($_post[' Q ')): ';
$time =isset ($_post[' time ')? Trim ($_post[' time '): ";
$chang =isset ($_post[' Chang '])? Trim ($_post[' Chang '): ";
$shi =isset ($_post[' shi ')) trim ($_post[' Shi '): ";
$id =isset ($_post[' id '))? Trim ($_post[' id '): ';//value
if (empty ($XM)) die ("Name cannot be empty");
if (empty ($id)) die ("ID cannot be empty");
if (empty ($time)) Die ("Time cannot be empty");
if (empty ($chang)) Die ("The site cannot be empty");
if (empty ($shi)) Die ("Precautions cannot be empty");
$time =time ();
$sql = "Update Bisai set name= ' $xm ', time= ' $time ', address= ' $chang ', zhu= ' $shi ' where id= ' $id '";//change on Demand
$a =mysqli_query ($link, $sql);
if ($a) {
echo "modified successfully";
Header ("location:zeng.php");
}else{
echo "failed to modify";
Header ("location:zeng.php");
}
?>
Original database connection