Jump to content

unidentified index i need help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
19 replies to this topic

#1
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
heres my database..

Quote

--
-- Database: `h_reservation`
-- --------------------------------------------------------
-- Table structure for table `guest_info`
--

CREATE TABLE IF NOT EXISTS `guest_info` (
`guest_id` int(11) NOT NULL AUTO_INCREMENT,
`room_type` varchar(25) NOT NULL,
`check_in` date NOT NULL,
`check_out` date NOT NULL,
PRIMARY KEY (`guest_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;
heres my code

<?php
    $single = "single room";
    $double = "double room";
    $standard = "standard twin";
    $deluxe = "deluxe double";    
    $mode = "no selected";
?>

<!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>Untitled Document</title>
</head>

<body>
<form action="getreserve3.php" method="get">
<select name="room"  >
  <option value="single room">single room</option>
  <option value="double room">double room</option>
  <option value="standard">standard twin</option>
  <option value="deluxe">deluxe double</option>
</select>
<input type=submit value=GENERATE>
</form>





<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "h_reservation";
$connection = @mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
$db = @mysql_select_db($database) or die("Can not select the database: ".mysql_error());


if($_GET)
{            
                    if($single){
                        $mode = "single room";
                    }
                    else if($double){
                        $mode = "double room";
                    }
                    else if($standard){
                        $mode = "standard twin";
                    }                    
                    else if($deluxe){
                        $mode = "deluxe double!";
                    }
                    else 
                        $mode="null";
                        
                    
                    echo "
                        <h3> room type : $mode </h3>
                        <hr>
                    ";}
            


//DISPLAYING CONTENT!!

$select = mysql_query("SELECT * FROM guest_info where room_type = '$mode'"); 

$total = 0;

while($row = mysql_fetch_array($select)){

echo $row['guest_id'] . "<br>" . "<br>";

$total = $total + 1 ;

}

//COUNTING CONTENT 
echo "-----------------total number of reservation-----------------------" . "<br>" . "<br>";
echo $total;


?>

</body>
</html>

when i run this theres no error but.. it always return single room value :crying:
i dont know where the error is anyone? i need help with this
thanks a lot :love:

Edited by hardinera, 11 March 2010 - 06:06 PM.


#2
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
remove the follwoing code
<?php

    $single = "single room";

    $double = "double room";

    $standard = "standard twin";

    $deluxe = "deluxe double";    

    $mode = "no selected";

?>


replace
if($_GET)

{            

                    if($single){

                        $mode = "single room";

                    }

                    else if($double){

                        $mode = "double room";

                    }

                    else if($standard){

                        $mode = "standard twin";

                    }                    

                    else if($deluxe){

                        $mode = "deluxe double!";

                    }

                    else 

                        $mode="null";

                        

                    

                    echo "

                        <h3> room type : $mode </h3>

                        <hr>

                    ";}

with

$mode = $_GET["room"]

But, I've not tried :)

#3
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
yay! its working! hehehe thanks :D but its returning undefined variable at this line

$select = mysql_query("SELECT * FROM guest_info where room_type = '$mode'"); 

:)

#4
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
for debugging :

$select = mysql_query("SELECT * FROM guest_info where room_type = '$mode'");  
if (!$select) {
    echo mysql_error();
}

while($row = mysql_fetch_array($select)){

echo $row['guest_id'] . "<br>" . "<br>";

$total = $total + 1 ;

}

if you use $row['guest_id'], usually we use mysql_fetch_assoc not mysql_fetch_array

#5
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
it says...

Quote

Undefined index: room

in this line

$mode = $_GET["room"] ;

heres my code -.-

<!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>Untitled Document</title>
</head>

<body>
<form action="getreserve3.php" method="get">
<select name="room" >
  <option value="select" selected="selected">select  room type</option>
  <option value="single room">single room</option>
  <option value="double room">double room</option>
  <option value="standard twin">standard twin</option>
  <option value="deluxe double">deluxe double</option>

</select>
<input type=submit value=GENERATE>
</form>


<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "h_reservation";
$connection = @mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
$db = @mysql_select_db($database) or die("Can not select the database: ".mysql_error());
 
$mode = $_GET["room"] ;
                    
echo "<h3> room type : $mode </h3><hr>";

//DISPLAYING CONTENT!!

$select = mysql_query("SELECT * FROM guest_info where room_type = '$mode'"); 
if (!$select) {
    echo mysql_error();
} 
$total = 0;

while($row = mysql_fetch_assoc($select)){

echo "guest id : ". " " . $row['guest_id'] 
. $row['room_type']  . "<br>"
. " " . $row['check_in'] . " " . "to" ." "  
. " " . $row['check_out'] 

. "<br>" . "<br>";

$total = $total + 1 ;

}

echo "<hr>";

//COUNTING CONTENT 
echo "<h1>-----------------total number of reservation-----------------------</h1>" . "<br>" . "<br>";
echo "<h1>  $total </h1><hr>";

?>

</body>
</html>


#6
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
replace
<form action="getreserve3.php" method="get">
$mode = $_GET["room"] ;

with
<form method="post">
$mode = $_POST["room"] ;

<form action="getreserve3.php" method="get"> means if you click generate button, It will move to getreserve3.php file, in this file you can get mode from $_GET['room']

#7
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
i edi do that but still getting that unidentified index -.-

um... im just calling the same page whenever i click generate..
<form action="getreserve3.php" method="get">


#8
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
I've tried you code, run as expected

Here is your code (with some edit)

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="room.php" method="get">
<select name="room" >
  <option value="select" selected="selected">select  room type</option>
  <option value="single room">single room</option>
  <option value="double room">double room</option>
  <option value="standard twin">standard twin</option>
  <option value="deluxe double">deluxe double</option>

</select>
<input type=submit value=GENERATE>
</form>


<?php
 
$mode = $_GET["room"] ;
                    
echo "<h3> room type : $mode </h3><hr>";
?>


</body>
</html>

Name of file is room.php

In your case, you must save file with name is getreserve3.php

Which line had an error?

#9
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
i saved the file as getreserve3.php when i click generate its just calling it self...
this error only appears when i load the page..

the line i have unidentified is this
$mode = $_POST["room"] ;

Quote

Notice: Undefined index: room


after placing some values on the box and clicking generate its gone.. -.- now im confused

#10
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
Please try the following code. Save it as room.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="room.php" method="get">
<select name="room" >
  <option value="select" selected="selected">select  room type</option>
  <option value="single room">single room</option>
  <option value="double room">double room</option>
  <option value="standard twin">standard twin</option>
  <option value="deluxe double">deluxe double</option>

</select>
<input type=submit value=GENERATE>
</form>


<?php

print('<pre>');
print_r($_GET);
print('</pre>');
$mode = $_GET["room"] ;
                    
echo "<h3> room type : $mode </h3><hr>";
?>


</body>
</html>

just a drop of dew in the morning
( loop while (= x true) do (x) )

#11
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
it returns

Quote

Array
(
)

unidentified index....


#12
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
ya, but if you select combobox then click on generate

Result if you selected single room:

Quote

Array
(
[room] => single room
)

room type : single room

just a drop of dew in the morning
( loop while (= x true) do (x) )