heres my database..
heres my code--
-- 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 ;
when i run this theres no error but.. it always return single room valueCode:<?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>
i dont know where the error is anyone? i need help with this
thanks a lot![]()
Last edited by hardinera; 03-11-2010 at 06:06 PM.
remove the follwoing code
Code:<?php
$single = "single room";
$double = "double room";
$standard = "standard twin";
$deluxe = "deluxe double";
$mode = "no selected";
?>
replace
withCode: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>
";}
But, I've not triedCode:$mode = $_GET["room"]
![]()
yay! its working! hehehe thanksbut its returning undefined variable at this line
Code:$select = mysql_query("SELECT * FROM guest_info where room_type = '$mode'");
![]()
for debugging :
Code:$select = mysql_query("SELECT * FROM guest_info where room_type = '$mode'");
if (!$select) {
echo mysql_error();
}
if you use $row['guest_id'], usually we use mysql_fetch_assoc not mysql_fetch_arrayCode:while($row = mysql_fetch_array($select)){
echo $row['guest_id'] . "<br>" . "<br>";
$total = $total + 1 ;
}
it says...
in this lineUndefined index: room
heres my code -.-Code:$mode = $_GET["room"] ;
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>
replace
withCode:<form action="getreserve3.php" method="get">
$mode = $_GET["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']Code:<form method="post">
$mode = $_POST["room"] ;
i edi do that but still getting that unidentified index -.-
um... im just calling the same page whenever i click generate..
Code:<form action="getreserve3.php" method="get">
I've tried you code, run as expected
Here is your code (with some edit)
Name of file is room.phpCode:<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>
In your case, you must save file with name is getreserve3.php
Which line had an error?
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
Code:$mode = $_POST["room"] ;
Notice: Undefined index: room
after placing some values on the box and clicking generate its gone.. -.- now im confused
Please try the following code. Save it as room.php
Code:<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) )
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks