dtlrp119999 2017-01-12 22:20
浏览 38
已采纳

在代码中出现意外的'=',试图在一个php文件中执行两个SQL查询

I m trying to get the existing "usercouponinhand" value from "userpaytoget" table and add it to received 'id' value as from "GET" tag. Then update it to the same "userpaytoget" table "usercouponinhand" column.

But unfortunately i see this "Unexpected =" error on the line result = $conn->query($sql);

The code follows:

<?php include('usercoupondelete.php'); ?>
<?php
$servername  = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "";

$mobile = $_SESSION['mobile'];
$date = date('M-d,Y H:i:s');
$date2 = date('M-d,Y');

$conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM userpaytoget WHERE mobile = '$mobile' ";
result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {

$usercouponinhand = $row["usercouponinhand"];
$couponvalue = $_GET["id"];
$totalvalue = $couponvalue + $usercouponinhand ;

$sql2 = "UPDATE userpaytoget SET usercouponinhand = '$totalvalue', date = '$date', date2 = '$date2'
WHERE mobile = '$mobile'";

if ($conn->query($sql2) === TRUE) {
echo  '<a href="usercoupondelete"></a>';
}
else {
echo "ERROR" . $sql2 . "<br>" . $conn->error;
}

}
 } else {
echo "None";
} 
$conn->close();
?>

Any Help is greatly appreciated..

展开全部

  • 写回答

1条回答 默认 最新

  • 普通网友 2017-01-12 22:21
    关注

    You are missing a $

    It should be $result = $conn->query($sql);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部