qq_41453741
我喜欢严歌
采纳率0%
2019-05-07 16:50 阅读 401

微信小程序存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条回答 默认 最新

  • as_csdn 代码的灵魂是bug! 2019-05-07 17:30

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

    点赞 评论 复制链接分享

相关推荐