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

时间:2017-01-13 06:20:35

标签: php mysql

我试图从“userpaytoget”表中获取现有的“usercouponinhand”值,并将其添加到“GET”标记中的“id”值。然后将其更新为相同的“userpaytoget”表“usercouponinhand”列。

但遗憾的是,我在行result = $conn->query($sql);

上看到了这个“意外=”错误

代码如下:

<?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();
?>

非常感谢任何帮助..

1 个答案:

答案 0 :(得分:0)

您错过了$

应为$result = $conn->query($sql);