1

I'm getting the following error :

Warning : mysql_fetch_array() expects parameter 1 to be resource, boolean given in

and

Warning: Cannot modify header information - headers already sent by (output started at "Insert file location here" in "Insert File location here"on line

Here's my code

<?php
    if (isset($_GET['id']))
    {
        $con = mysql_connect("xxx.net","username","password") or die("Connection to server Failed");
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }

        mysql_select_db("itekniks_altaroca") or die("DB Selection Failed");
        $messages_id = $_GET['id'];
        $result3 = mysql_query("SELECT * FROM reservation where reservation_id ='$messages_id'");


        while($row3 = mysql_fetch_array($result3))
        {
            $res=$row3['confirmation'];
        }
        $update1=mysql_query("UPDATE reservation SET status ='out' WHERE reservation_id ='$messages_id'");
        $update2=mysql_query("UPDATE roominventory SET status ='out' WHERE confirmation = '$res'");
        header("location: home_admin.php#1");

        exit();

        mysql_close($con);
    }
?>
Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
Patrick
  • 23
  • 2

2 Answers2

1
<?php
    if (isset($_GET['id']))
    {
        $con = mysql_connect("xxxx.net","username","password") or die("Connection to server Failed");
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }

        mysql_select_db("xxxxdb") or die("DB Selection Failed");
        $messages_id = $_GET['id'];
        $result = mysql_query("SELECT * FROM reservation where reservation_id ='$messages_id'");

        if($result === FALSE) { 
            die(mysql_error()); // TODO: better error handling
        }

        while($row3 = mysql_fetch_array($result3))
        {
            $res=$row3['confirmation'];
        }
        $update1=mysql_query("UPDATE reservation SET status ='out' WHERE reservation_id ='$messages_id'");
        $update2=mysql_query("UPDATE roominventory SET status ='out' WHERE confirmation = '$res'");
        header("location: home_admin.php#1");

        exit();

        mysql_close($con);
    }
?>

maybe you choose the undefined reservation table there. or there is no column reservation_id


add this before mysql_fetch_array

        if($result === FALSE) { 
            die(mysql_error()); // TODO: better error handling
        }

UPDATED my code here:

<?php
    if (isset($_GET['id']))
    {
        $con = mysql_connect("xxxx.net","username","password") or die("Connection to server Failed");
        if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }

        mysql_select_db("xxxxdb") or die("DB Selection Failed");
        $messages_id = $_GET['id'];
        $result = mysql_query("SELECT * FROM reservation where reservation_id ='$messages_id'");

        if($result === FALSE) { 
            die(mysql_error()); // TODO: better error handling
        }

        $row = mysql_fetch_array($result);
        $confirmation = $row['confirmation'];
        $update1=mysql_query("UPDATE reservation SET status ='out' WHERE reservation_id ='$messages_id'");
        $update2=mysql_query("UPDATE roominventory SET status ='out' WHERE confirmation = '$confirmation'");
        header("location: home_admin.php#1");

        exit();

        mysql_close($con);
    }
?>
  1. there is no column reservation_id in your reservation table
Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
  • I tried that too and it is giving me the same output "Unknown column 'reservation_id' in 'where clause" Is it because there's no reservation_id in the database? Sorry for the noob question, I'm not really experienced with php :/ and Thanks for replying! – Patrick May 10 '15 at 09:18
  • @Patrick just check this as an answer thank you Pat – Josua Marcel C May 10 '15 at 09:20
  • checked it, and should I just add a reservation_id on the database? Thanks again. – Patrick May 10 '15 at 09:26
  • @Patrick yeah just add it, but you should know the connection with room_id and message id that you've created there – Josua Marcel C May 11 '15 at 01:12
  • 1
    Thanks for the help and tips! its up and running now :) – Patrick May 11 '15 at 15:00
1

First of all you just have to print $result3 and see what it returns.

Also, you may try:

$result3 = mysql_query("SELECT * FROM reservation where reservation_id=".$messages_id);
Magnilex
  • 11,584
  • 9
  • 62
  • 84