-2

I got this problem when running in my view_reservation.php. It didn't view my following records in database. Below is the code in view_reservation.php

The Error Says Line 89. is where the "WHILE" is located:

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

The code:

<?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'];
mcuadros
  • 4,098
  • 3
  • 37
  • 44
  • This is not safe application. Also, you're using `mysql_*` functions. It is not recommended. – Daniel Kmak Feb 21 '14 at 22:21
  • Please don't down grade my post i'm beginner in PHP so i'm still learning thank you. and if there's any suggestion on how do i solve or change for safe coding. can u tell me? – user3265633 Feb 21 '14 at 22:24
  • Hello Daniel, is there anyway of other coding or code that can solve this problem? – user3265633 Feb 21 '14 at 22:26
  • `$id = $_GET['reservation_id'];` - this is unsafe - users can destroy your database. You can use `$id = (int)$_GET['reservation_id'];` instead. You should also use `mysqli_*` functions or PDO. Mysqli prepared statements are great. It is obvious that you're getting an error because your query fails. Please try to copy this query into, for example, phpMyAdmin and see what errors you get. @vlzvl I agree. – Daniel Kmak Feb 21 '14 at 22:26
  • 1
    Whats the point of downvoting a troubled OP? Is this question unclear or hasnt shown any effort? Point him using `mysqli_` or `PDO` in an answer, not downvoting him. –  Feb 21 '14 at 22:27
  • If you're just learning, [forget what you've learned about connecting to MySQL immediately](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) and [learn a different method](http://ca2.php.net/manual/en/book.pdo.php). – miken32 Feb 21 '14 at 22:31
  • ok2, thank you for all the comments and suggestion i will search and study new method, i'm just new in PHP environment and don't know much about it. because i'm still a 1st year IT student. thank you – user3265633 Feb 21 '14 at 22:36
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – andrewsi Feb 22 '14 at 00:07

1 Answers1

0

I copied your code to MySQL Syntax Check and it printed an error about your first line. I deleted unnecessary spaces and syntax is ok now. Please try this code:

<?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'];

?>

Also, consider moving from mysql_* functions to mysqli_* or PDO.

Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89