Original database connection

Source: Internet
Author: User

<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

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.