Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告:mysqli_query()要求参数2为字符串,对象为给定的_Php_Mysqli - Fatal编程技术网

Php 警告:mysqli_query()要求参数2为字符串,对象为给定的

Php 警告:mysqli_query()要求参数2为字符串,对象为给定的,php,mysqli,Php,Mysqli,有人能帮我解决这个错误吗 警告:mysqli_查询要求参数2为字符串,对象为给定。。第25行 名为query的变量应仅为。。。质疑 $result=mysqli_query$con,从预订中选择*,其中r_date='.$date' 此外,即使您认为您将获得一条记录,也可以使用函数mysqli\u fetch\u array 将始终返回一个数组。因此,您需要选择数组中的第一项,然后选择键或索引 $price=$row[0]['combo_price'] 一些代码实践。不要把所有的东西都放在你的I

有人能帮我解决这个错误吗

警告:mysqli_查询要求参数2为字符串,对象为给定。。第25行


名为query的变量应仅为。。。质疑

$result=mysqli_query$con,从预订中选择*,其中r_date='.$date'

此外,即使您认为您将获得一条记录,也可以使用函数mysqli\u fetch\u array 将始终返回一个数组。因此,您需要选择数组中的第一项,然后选择键或索引

$price=$row[0]['combo_price']

一些代码实践。不要把所有的东西都放在你的IF里。因为如果失败,$payment将是未定义的,并抛出一个错误。在脚本上初始化它。您还需要存储mysqli_查询的返回值,因为您需要释放用于该查询的内存

mysqli_free_result$result


您的代码有多个问题。丢失的重复调用mysqli_查询、SQL注入和无错误检查

而不是在文件顶部使用if enable exceptions检查查询是否成功。使用预先准备好的语句,最好是以面向对象的方式

session_start();
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); //  this line enables exceptions
include 'includes/dbcon.php';

$stmt = $con->prepare('SELECT * FROM reservation WHERE r_date=?'); // ? is a placeholder for binding data
$stmt->bind_param('s', $date); // bind data to SQL statement as a string(s)
$stmt->execute();
$reservations = $stmt->get_result();

// if your SELECT found some record then loop on the result set fetching each row one by one
while ($row = $reservations->fetch_assoc()) {
    $combos = $con->query("SELECT * FROM combo where combo_id=1"); // if there is no data to be bound then we can use query
    $row = $combos->fetch_assoc(); // fetch the matching combo row
    $price = $row['combo_price'];
    $payable = $pax * $price;
}

什么是$query?定义在哪里?测试var$query,而不是if语句中的mysqli_查询操作您似乎缺少引号和;除了反复运行mysqli_query之外,我还假设您的意思是警告不冲突-两个复制/粘贴错误。
<?php 
session_start();
include('includes/dbcon.php');

// you're missing some syntax here.. 
// also your $query IS your query so it should be $query = "SELECT * FROM ";

$query = mysqli_query($con, "SELECT * FROM reservation WHERE r_date='".$date."'
// you don't need this above line.. it does it all right here...
if (!mysqli_query($con,$query))  
{
$query = mysqli_query($con, "SELECT * FROM combo where combo_id=1");
$row=mysqli_fetch_array($query);
$price=$row['combo_price'];
$payable=$pax*$price;
// missing closing brackets. }
session_start();
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); //  this line enables exceptions
include 'includes/dbcon.php';

$stmt = $con->prepare('SELECT * FROM reservation WHERE r_date=?'); // ? is a placeholder for binding data
$stmt->bind_param('s', $date); // bind data to SQL statement as a string(s)
$stmt->execute();
$reservations = $stmt->get_result();

// if your SELECT found some record then loop on the result set fetching each row one by one
while ($row = $reservations->fetch_assoc()) {
    $combos = $con->query("SELECT * FROM combo where combo_id=1"); // if there is no data to be bound then we can use query
    $row = $combos->fetch_assoc(); // fetch the matching combo row
    $price = $row['combo_price'];
    $payable = $pax * $price;
}