微信小程序存PHP数据库存不进去,提示Error: "?

微信小程序存PHP数据库存不进去,提示Error: "
addcar: function () {
//存入购物车
var that = this;
wx.request({
url:'http://localhost/cartsave.php',//此处填写你后台请求地址
method: 'POST',
header: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: {
newprice: that.data.detail.newprice,
goodspic: that.data.detail.goodspic,
goodsname: that.data.detail.goodsname,
size: that.data.detail.size
},
success: function (res) {
// success
console.log(res);//打印请求返回的结果
//that.setData({ listhot: res.data })

  },
  fail: function (res) {
    // fail
  },
  complete: function (res) {
    // complete
  }
});

PHP
<?php
//echo 666;
//$domain=$_POST['newprice'];
error_reporting(0);
//echo $domain;
//echo $_POST['newprice'];
$newprice=$_POST['newprice'];
$goodspic=$_POST['goodspic'];
$size=$_POST['size'];
$goodsid=$_POST['goodsid'];
$goodsname=$_POST['goodsname'];

$con=mysqli_connect("localhost","root","123456","wxstore");
if (!$con)
{

die('Could not connect: ' . mysqli_connect_error());
}

mysqli_query($con,"set names utf8");

if (!empty($newprice)&&!empty($goodspic)&&!empty($size)&&!empty($goodsname))
{
$sql="INSERT INTO carts (newprice, goodsid, goodspic,goodsname,size) VALUES (".$newprice.",'".$goodspic."','".$goodsname."',".$size.")";
//$sql="SELECT * FROM carts";
echo $sql;
$result = mysqli_query($con,$sql);
if (!$result)
{

die('Error: ' . mysqli_connect_error());
}

}

// $sql1 = "SELECT * FROM carts";
// $result1 = mysqli_query($con,$sql1);

?>

1个回答

$sql="INSERT INTO carts (newprice, goodsid, goodspic,goodsname,size) VALUES (".$newprice.",'".$goodspic."','".$goodsname."',".$size.")";
你是不是少了一个参数哦goodsid

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐