Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: unidentified index i need help

  1. #1
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    unidentified index i need help

    heres my database..
    --
    -- 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

    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 ;

    }

    //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
    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.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    remove the follwoing code
    Code:
    <?php
        $single 
    "single room";
        
    $double "double room";
        
    $standard "standard twin";
        
    $deluxe "deluxe double";    
        
    $mode "no selected";
    ?>

    replace
    Code:
    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

    Code:
    $mode $_GET["room"
    But, I've not tried

  4. #3
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    yay! its working! hehehe thanks but its returning undefined variable at this line

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

  5. #4
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    for debugging :

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

    Code:
    while($row mysql_fetch_array($select)){

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

    $total $total ;


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

  6. #5
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    it says...
    Undefined index: room
    in this line

    Code:
    $mode $_GET["room"] ; 
    heres my code -.-
    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 : ""&nbsp;" $row['guest_id'
    $row['room_type']  . "<br>"
    "&nbsp;" $row['check_in'] . "&nbsp;" "to" ."&nbsp;"  
    "&nbsp;" $row['check_out'

    "<br>" "<br>";

    $total $total ;

    }

    echo 
    "<hr>";

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

    ?>

    </body>
    </html>

  7. #6
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    replace
    Code:
    <form action="getreserve3.php" method="get">
    $mode $_GET["room"] ; 
    with
    Code:
    <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']

  8. #7
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    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"

  9. #8
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    I've tried you code, run as expected

    Here is your code (with some edit)

    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
     
    $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?

  10. #9
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    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

  11. #10
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: unidentified index i need help

    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) )

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. A-Z Index
    By jwg2s in forum PHP Development
    Replies: 2
    Last Post: 06-07-2011, 08:54 AM
  2. Replies: 1
    Last Post: 07-20-2010, 12:46 PM
  3. Replies: 7
    Last Post: 01-24-2010, 10:02 PM
  4. z-index problem
    By tomitzel in forum JavaScript and CSS
    Replies: 1
    Last Post: 11-05-2009, 10:37 AM
  5. iframes on index.php
    By Hektor in forum Linux/Unix General
    Replies: 6
    Last Post: 11-14-2007, 06:12 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts