这是收到错误的代码:
session_start();
$user = $_SESSION["username"];
$sql = "SELECT cost FROM rooms
WHERE rid = $rNumber";
$results = mysqli_query($conn, $sql)
or die ('Problem with query' . mysqli_error($conn));
$row = mysqli_fetch_array($results);
$sql2 = "INSERT INTO bookings (rid, username, checkin, checkout, cost)
VALUES ($rNumber, $user, $cInDate, $cOutDate, $row['price'])"; //this line is where the error occurs
$results2 = mysqli_query($conn, $sql2)
or die ('Problem with query' . mysqli_error($conn));
我似乎遇到了这个错误:
unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
我已经尝试检查有关同一错误的其他帖子,我收集说我必须使用(。)连接一些东西,但我不知道是什么。我已经在sql之前回应了变量并且它们存在。
答案 0 :(得分:0)
请改变这一行。
$sql2 = "INSERT INTO bookings (rid, username, checkin, checkout, cost)
VALUES ('$rNumber', '$user', '$cInDate', '$cOutDate', '{$row['price']}')";
我还从您的查询中解决了MySql语法错误:P