Php mysql\u数组中出现错误
我在运行我的Php mysql\u数组中出现错误,php,mysql,Php,Mysql,我在运行我的视图\u reservation.php时遇到了这个问题。它没有在数据库中查看我的以下记录。 下面是view\u reservation.php 错误是第89行。是“WHILE”所在的位置: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\FINAL_THESIS\admin\view_reservation.php on line 89
视图\u reservation.php
时遇到了这个问题。它没有在数据库中查看我的以下记录。
下面是view\u reservation.php
错误是第89行。是“WHILE”所在的位置:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\FINAL_THESIS\admin\view_reservation.php on line 89
守则:
<?php
include('dbcon.php');
$id = $_GET['reservation_id'];
$customer_query=mysql_query("SELECT reservation.res_type ,reservation.type ,reservation.fname ,reservation.mname ,reservation.lname ,reservation.age ,reservation.address ,reservation.wfname ,reservation.wmname ,reservation.wlname ,reservation.sched_time ,reservation.sched_month ,reservation.sched_date ,reservation.sched_year ,reservation.cfname ,reservation.pd_name ,reservation.bd_month ,reservation.bd_date ,reservation.bd_year ,reservation.wbd_month ,reservation.wbd_date ,reservation.wbd_year ,reservation.w_age ,reservation.w_address ,reservation.status ,customer.firstname ,customer.middlename ,customer.lastname ,customer.email ,customer.age ,customer.gender ,customer.barangay ,customer.com_address ,reservation.res_id FROM customer Inner Join reservation
ON customer.cus_id = reservation.cus_id where res_id = '$id'");
while($cust_rows=mysql_fetch_array($customer_query)) {
if($cust_rows['gender'] == 'Male') {
$gender ='Mr.';
} else {
$gender ='Ms.';
}
$id=$cust_rows['cus_id'];
$fn=$cust_rows['firstname']." ".$cust_rows['middlename']." ".$cust_rows['lastname'];
$email=$cust_rows['email'];
$age=$cust_rows['age'];
$brgy=$cust_rows['barangay'];
$comp=$cust_rows['com_address'];
我将您的代码复制到,它打印了一个关于您的第一行的错误。我删除了不必要的空格,现在语法正常了。请尝试以下代码:
<?php
include('dbcon.php');
$id = (int)$_GET['reservation_id'];
$customer_query=mysql_query("SELECT reservation.res_type, reservation.type, reservation.fname, reservation.mname, reservation.lname, reservation.age, reservation.address, reservation.wfname, reservation.wmname, reservation.wlname, reservation.sched_time, reservation.sched_month, reservation.sched_date, reservation.sched_year, reservation.cfname, reservation.pd_name, reservation.bd_month, reservation.bd_date, reservation.bd_year, reservation.wbd_month, reservation.wbd_date, reservation.wbd_year, reservation.w_age, reservation.w_address,reservation.status, customer.firstname, customer.middlename, customer.lastname, customer.email, customer.age, customer.gender, customer.barangay, customer.com_address, reservation.res_id FROM customer INNER JOIN reservation
ON customer.cus_id = reservation.cus_id WHERE res_id ='$id'");
while($cust_rows=mysql_fetch_array($customer_query))
{
if($cust_rows['gender'] == 'Male')
{
$gender ='Mr.';
}
else
{
$gender ='Ms.';
}
$id=$cust_rows['cus_id'];
$fn=$cust_rows['firstname']." ".$cust_rows['middlename']." ".$cust_rows['lastname'];
$email=$cust_rows['email'];
$age=$cust_rows['age'];
$brgy=$cust_rows['barangay'];
$comp=$cust_rows['com_address'];
?>
也可以考虑从<代码> MySqL**<代码>函数移动到<代码> MySqLix*< /Cord>或./P>这是不安全的应用程序。另外,您正在使用
mysql.*
函数。不推荐。请不要贬低我的帖子。我是PHP初学者,所以我还在学习。谢谢。如果有任何关于如何解决或更改安全编码的建议。你能告诉我吗?你好,丹尼尔,还有其他编码或代码可以解决这个问题吗代码>-这是不安全的-用户可以破坏您的数据库。您可以使用$id=(int)$\u GET['reservation\u id']代码>取而代之。您还应该使用mysqli.*
函数或PDO。Mysqli编写的语句很棒。很明显,由于查询失败,您将得到一个错误。请尝试将此查询复制到例如phpMyAdmin中,并查看您得到的错误@vlzvl我同意。否决一个有问题的行动有什么意义?这个问题是否不清楚或没有表现出任何努力?在回答中指出他使用的是mysqli
或PDO
,而不是否决他。我只是添加了它并应用了它,然后我将使用mysqli
。谢谢,没问题。祝你好运