Can anyone tell me what wrong with this please!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fang

    Can anyone tell me what wrong with this please!

    Hi,
    I'm new to PHP. I followed an example on the book and wanted to pass a variable
    from one html page to a php page, but it always tells me the passed variable is
    undefined. I've checked the syntax over and over again, but I couldn't find the
    problem. I also tried to change POST to SUBMIT and noticed the value of the
    variable can be passed. Why can't the target php catch it??? The code is as
    following, can any one please kindly help me out?
    Very much appreciated!

    ----------------------HOME.htm----------------------------------------------------
    <html >
    <head>
    <script language="JavaS cript" type="text/javascript">
    function book(show) {
    if (!show.contains (event.toElemen t)) {
    document.showLi st.where.value = show.name;
    document.showLi st.submit();
    }
    }
    </script>
    </head>
    <title>Home</title>
    <body>
    <form name="showList" method="POST" action="test.ph p">
    <input type="hidden" name="where">
    <input type="button" value="BOOK" name="LaBotieII " onClick="book(t his)">
    </body>
    </html>
    -------------------------------TEST.php----------------------------------------------
    <html >
    <head>
    </head>
    <title>TEST</title>
    <body>
    <?php
    include("connec tion.php"); //connect to a database
    connect();
    echo($whichVenu e); //error message "whichVenue is undefined"
    $ven =whichVenue; //error message "whichVenue is undefined"
    ?>
    </body></html>


  • ohdarn

    #2
    Re: Can anyone tell me what wrong with this please!

    What's in your 'connection.php ' file? Do you mind posting that without
    the database information(i.e . username, password, etc.).

    Ohdarn

    Comment

    • micha

      #3
      Re: Can anyone tell me what wrong with this please!

      what your html page passes as far as i can see the code is

      $_POST['where'] = '' (empty)
      $_POST['LaBotieII'] = 'BOOK'

      Comment

      • Geoff Berrow

        #4
        Re: Can anyone tell me what wrong with this please!

        I noticed that Message-ID: <d44cit$29s4$1@ bunyip2.cc.uq.e du.au> from
        Fang contained the following:
        [color=blue]
        >I'm new to PHP. I followed an example on the book[/color]
        Please let us know which book is recommending solutions that rely on
        Javascript to operate so that we can avoid it.

        This may get you going:

        ----------------------HOME.htm----------------------------------------------------
        <html >
        <head>
        <title>Home</title>
        </head>

        <body>
        <form method="POST" action="test.ph p">
        <select name='show'>
        <option>Show 1</option>
        <option>Show 2</option>
        <option>Show 3</option>
        <option>Show 4</option>
        </select>
        <input type="submit" value="submit" name="Book" >
        </body>
        </html>
        -------------------------------TEST.php----------------------------------------------
        <html >
        <head>
        <title>TEST</title>
        </head>
        <body>
        <?php
        if (isset($_POST['show'])){
        echo "<p>You selected " .$_POST['show']."</p>";
        }
        ?>
        <a href="home.htm" > Book another?</a>
        </body>
        </html>



        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Micha³ Wo¼niak

          #5
          Re: Can anyone tell me what wrong with this please!

          One quick glance of an experienced eye allowed to understand the blurred
          and almost unreadable Fang's handwriting:
          [color=blue]
          > Hi,
          > I'm new to PHP. I followed an example on the book and wanted to pass a
          > variable from one html page to a php page, but it always tells me the
          > passed variable is undefined. I've checked the syntax over and over
          > again, but I couldn't find the problem. I also tried to change POST to
          > SUBMIT and noticed the value of the
          > variable can be passed. Why can't the target php catch it??? The code
          > is as following, can any one please kindly help me out?
          > Very much appreciated!
          >
          >[/color]
          ----------------------HOME.htm----------------------------------------------[color=blue]
          > <html >
          > <head>
          > <script language="JavaS cript" type="text/javascript">
          > function book(show) {
          > if (!show.contains (event.toElemen t)) {
          > document.showLi st.where.value = show.name;
          > document.showLi st.submit();
          > }
          > }
          > </script>
          >
          > </head>
          >
          > <title>Home</title>[/color]

          The <title></title> tag should be placed inside the <head></head>
          section.
          [color=blue]
          > <body>
          > <form name="showList" method="POST" action="test.ph p">
          > <input type="hidden" name="where">
          > <input type="button" value="BOOK" name="LaBotieII "
          > onClick="book(t his)">[/color]

          Why don't you close the <form> tag?
          [color=blue]
          > </body>
          >
          > </html>
          >[/color]

          -------------------------------TEST.php-------------------------------------[color=blue]
          > <html >
          > <head>
          > </head>
          > <title>TEST</title>
          > <body>
          > <?php
          > include("connec tion.php"); //connect to a database
          > connect();
          > echo($whichVenu e); //error message "whichVenue is undefined"
          > $ven=whichVenue ; //error message "whichVenue is undefined"[/color]

          You don't post any variable that is named whichVenue. You post a variable
          named "where" (accessible through $_POST['where']) whith value
          'LaBottieII" as far as I can see, and a variable named
          'LaBottieII' ($_POST['LaBottieII']) whith value 'BOOK'. No more, no
          less.
          [color=blue]
          > ?>
          > </body></html>[/color]

          Cheers
          Mike

          Comment

          Working...