一尘不染

mysql_fetch_assoc()期望参数1为资源,在第9行的C:\ xampp \ htdocs \ qcc \ truckdelivery.php中给定布尔值,未选择数据库

mysql

<?php require_once('Connections/connect.php'); ?>
<?php
 $id_truck = mysql_real_escape_string($_GET['id_truck']);
 $sql_PK = "SELECT * FROM tbl_truck WHERE id_truck = '{$id_truck}'";
 $res_PK = mysql_query($sql_PK, $connect);
 $row_PK = mysql_fetch_assoc($res_PK);
 $truck_plate = $row_PK['truck_plate_no'];
 $truck_plate = mysql_real_escape_string($truck_plate);

 $sql = "SELECT tbl_truck.truck_plate_no, 
    tbl_delivery_details.delivery_details_route, 
    tbl_delivery_details.delivery_details_destination, 
    tbl_delivery_details.delivery_details_van_no, 
    tbl_delivery_details.delivery_details_waybill_no, 
    tbl_delivery_details.delivery_details_charge_invoice,
    tbl_delivery_details.delivery_details_revenue,
    tbl_delivery_details.delivery_details_strip_stuff,
    tbl_delivery_details.delivery_details_date
    FROM tbl_truck, tbl_delivery_details 
    WHERE tbl_truck.truck_plate_no = tbl_delivery_details.tbl_truck_id_truck 
    AND tbl_truck.truck_plate_no = '{$truck_plate}'";

$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($res);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Truck Delivery</title>
<link rel="stylesheet" type="text/css" href="qcc.css"/>
</head>
<body>
<?php echo $row_PK['delivery_details_route'];?>
</body>
</html>

mysql_fetch_assoc()期望参数1为资源,在第9行的C:\ xampp \ htdocs \ qcc \
truckdelivery.php中给定布尔值,未选择数据库

我不知道我在哪里弄错了代码;此页面是一个表格的链接,该表格中我塞满了所有车牌号,然后使用此代码将车牌号变成了链接。

href="truckdelivery.php?id_truck=<?php echo $row_truck['id_truck']?>"><?php echo    $row_truck['truck_plate_no'];

阅读 228

收藏
2020-05-17

共1个答案

一尘不染

在处理查询结果之前,请检查MySQL错误。您的查询很可能以某种方式出错,因此mysql_query()未返回有效结果,因此mysql_fetch_assoc()失败。

// ...
$PK = mysql_query($sql_PK, $connect);
if ( mysql_error() ) {
  die ( mysql_error();
}
$row_PK = mysql_fetch_assoc($PK);
// ...

此外:mysql_x()不推荐使用功能。请改用PDOMySQLi

2020-05-17