-
Notifications
You must be signed in to change notification settings - Fork 0
/
deletecart.php
59 lines (46 loc) · 1.71 KB
/
deletecart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
header("Access-Control-Allow-Origin: http://localhost:8080");
//定义需要获取数据库的数据
// echo 6666;
$cartid = $_POST["cartid"];
$cartnum = $_POST["cartnum"];
$cartmsg = $_POST["cartmsg"];
$cartprice = $_POST["cartprice"];
$cartimg = $_POST["cartimg"];
class Goods{
public $cartid;
public $cartnum;
public $cartmsg;
public $cartprice;
public $cartimg;
}
// var data1 = file_get_contents("php://input");
// console.log(data1)
//连接数据库
// $conn = new mysqli("127.0.0.1","root","","shijianfeishi") or die("连接失败!");
require 'mysql666.php';
$conn->query("set names utf8"); //设置编码为utf8
$sql = "select * from cart";
$sql = "delete from cart where cartid = '".$cartid."'";
// $sql = "insert into cart (cartid,cartnum,cartmsg,cartprice,cartimg) values ('168','$cartnum','$cartnum','1','1')";
$result = $conn->query($sql);//执行数据库命令返回数据
if($result->num_rows > 0){//$result->num_rows == 返回的数据
$arr = array();
while($row = $result->fetch_assoc()){//循环整个数据每次拿出一条
$goods = new Goods();
$goods->cartid = $row["cartid"];
$goods->cartnum = $row["cartnum"];
$goods->cartmsg = $row["cartmsg"];
$goods->cartprice = $row["cartprice"];
$goods->cartimg = $row["cartimg"];
// echo $row["goodsname"];
array_push($arr, $goods);
}
//返回json字符串
echo json_encode($arr);
}
else {
echo "";
}
$conn->close();
?>