Missing something in passing form variables

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

    Missing something in passing form variables

    I have the following code to select an item from a drop down menu and
    call the same script over again. I am expecting that after the first
    time the script is run the first echo would produce the selected PBX
    name (e.g. FMSite) but instead I get FMSitepbx=FMSit e.

    Needless to say this screws up the further processing I want to do. What
    I really want to do is set a cookie containing the selected PBX name so
    other scripts can get the cookie and provide specific data.

    Thanks,

    Mike


    <?php


    echo($_POST['pbx']);
    $dbcnx = @mysql_connect( "localhost" , "***", "********** ");
    if (!dbcnx){
    echo( "<p>Unable to connect to database.</p>");
    exit();
    }
    if ( !@mysql_select_ db("inet") ) {
    echo( "<p> Unable to locate the iNet database. " . mysql_error() .
    "</p>" );
    exit ();
    }

    $query = 'Select Name from PBX order by Name';
    $result = mysql_query ($query)
    or die ('Query Failed');
    echo '<form action="setpbx. php" method="POST">' ;
    echo 'Select PBX <select name="pbx">';
    while ($row = mysql_fetch_arr ay ($result)) {
    echo '<option value="' . $row['Name'] . '">' . $row['Name'];
    }
    echo '</select>';
    echo '<input type="submit" value="Submit"> ';
    echo '</form>';

    ?>
  • Pedro Graca

    #2
    Re: Missing something in passing form variables

    Mike Wilcox wrote:[color=blue]
    > I have the following code to select an item from a drop down menu and
    > call the same script over again. I am expecting that after the first
    > time the script is run the first echo would produce the selected PBX
    > name (e.g. FMSite) but instead I get FMSitepbx=FMSit e.[/color]
    [snip][color=blue]
    > <?php
    >
    >
    > echo($_POST['pbx']);[/color]
    [snip]

    Try this instead:

    echo ' *** ', $_POST['pbx'];


    My suspicion is that the "FMSitepbx= " is written before your script
    reaches that particular point (and maybe this proves me right).
    --
    mail sent to my From: address is publicly readable at www.mailinator.net
    I probably will never read it (possibly some one else will).

    Comment

    • Mike Wilcox

      #3
      Re: Missing something in passing form variables

      Pedro Graca <hexkid@mailina tor.com> wrote in
      news:slrncp7uqc .vko.hexkid@ID-203069.user.uni-berlin.de:
      [color=blue]
      > Mike Wilcox wrote:[color=green]
      >> I have the following code to select an item from a drop down menu and
      >> call the same script over again. I am expecting that after the first
      >> time the script is run the first echo would produce the selected PBX
      >> name (e.g. FMSite) but instead I get FMSitepbx=FMSit e.[/color]
      > [snip][color=green]
      >> <?php
      >>
      >>
      >> echo($_POST['pbx']);[/color]
      > [snip]
      >
      > Try this instead:
      >
      > echo ' *** ', $_POST['pbx'];
      >
      >
      > My suspicion is that the "FMSitepbx= " is written before your script
      > reaches that particular point (and maybe this proves me right).[/color]

      Output is ***FMSitepbx=FM Site

      Mike

      Comment

      • denisb

        #4
        Re: Missing something in passing form variables

        Mike Wilcox <mike.j.wilcox@ intel.com> wrote:[color=blue]
        > Pedro Graca <hexkid@mailina tor.com> wrote in
        > news:slrncp7uqc .vko.hexkid@ID-203069.user.uni-berlin.de:[color=green]
        > > Try this instead:
        > > echo ' *** ', $_POST['pbx'];[/color]
        > Output is ***FMSitepbx=FM Site[/color]

        maybe a bad html construction
        you should verify your 'pbx' value in your html page
        by reading your html source code

        --
        @@@@@
        E -00 comme on est very beaux dis !
        ' `) /
        |\_ =="

        Comment

        • Pedro Graca

          #5
          Re: Missing something in passing form variables

          Mike Wilcox wrote:[color=blue]
          > Pedro Graca <hexkid@mailina tor.com> wrote in
          > news:slrncp7uqc .vko.hexkid@ID-203069.user.uni-berlin.de:
          >[color=green]
          >> Mike Wilcox wrote:[color=darkred]
          >>> echo($_POST['pbx']);[/color]
          >> [snip]
          >>
          >> Try this instead:
          >>
          >> echo ' *** ', $_POST['pbx'];
          >>
          >>
          >> My suspicion is that the "FMSitepbx= " is written before your script
          >> reaches that particular point (and maybe this proves me right).[/color]
          >
          > Output is ***FMSitepbx=FM Site[/color]
          ^^
          No space here? ?!?!?!

          Can we have a look at your site to see the HTML generated?
          [color=blue][color=green][color=darkred]
          >>> while ($row = mysql_fetch_arr ay ($result)) {
          >>> echo '<option value="' . $row['Name'] . '">' . $row['Name'];[/color][/color][/color]
          /* it doesn't matter, but I'd add */
          echo '</option>';[color=blue][color=green][color=darkred]
          >>> }[/color][/color][/color]

          --
          mail sent to my From: address is publicly readable at www.mailinator.net
          I probably will never read it (possibly some one else will).

          Comment

          • Mike Wilcox

            #6
            Re: Missing something in passing form variables

            Pedro Graca <hexkid@mailina tor.com> wrote in
            news:slrncp981q .vko.hexkid@ID-203069.user.uni-berlin.de:
            [color=blue]
            > Mike Wilcox wrote:[color=green]
            >> Pedro Graca <hexkid@mailina tor.com> wrote in
            >> news:slrncp7uqc .vko.hexkid@ID-203069.user.uni-berlin.de:
            >>[color=darkred]
            >>> Mike Wilcox wrote:
            >>>> echo($_POST['pbx']);
            >>> [snip]
            >>>
            >>> Try this instead:
            >>>
            >>> echo ' *** ', $_POST['pbx'];
            >>>
            >>>
            >>> My suspicion is that the "FMSitepbx= " is written before your script
            >>> reaches that particular point (and maybe this proves me right).[/color]
            >>
            >> Output is ***FMSitepbx=FM Site[/color]
            > ^^
            > No space here? ?!?!?!
            >
            > Can we have a look at your site to see the HTML generated?
            >[color=green][color=darkred]
            >>>> while ($row = mysql_fetch_arr ay ($result)) {
            >>>> echo '<option value="' . $row['Name'] . '">' . $row['Name'];[/color][/color]
            > /* it doesn't matter, but I'd add */
            > echo '</option>';[color=green][color=darkred]
            >>>> }[/color][/color]
            >[/color]

            The site is on an intranet only and is not accessible from the internet.
            Here is the HTML source as captured from my browser (IE 6)

            Thanks,

            Mike

            <html>
            <head>
            <title>iNet Information Database - Set PBX</Title>
            </head>
            <body>
            <H1><center>iNe t Data Homepage - PBX Selection</center></H1>
            <br><br>


            ***FMSitepbx=FM Site end <form action="setpbx. php" method="POST">
            Select PBX <select name="pbx"><opt ion value="FMSite"> FMSite<option
            value="PG12">PG 12</select>
            <input type="submit" value="Submit"> </form>




            </body>
            </html>

            Comment

            • Pedro Graca

              #7
              Re: Missing something in passing form variables

              Mike Wilcox wrote:[color=blue]
              > Here is the HTML source as captured from my browser (IE 6)[/color]

              Your php code, with a few changes, works as expected for me.
              Run it on your server:


              <html>
              <head>
              <title>xxx</title>
              </head>
              <body>

              <?php

              error_reporting (E_ALL);
              ini_set('displa y_errors', '1');

              echo($_POST['pbx']);

              // $dbcnx = @mysql_connect( "localhost" , "***", "********** ");
              // if (!dbcnx) {
              // echo "<p>Unable to connect to database.</p>";
              // exit();
              // }

              // if (!@mysql_select _db("inet")) {
              // echo "<p> Unable to locate the iNet database. ", mysql_error(), "</p>";
              // exit();
              // }

              // $query = 'Select Name from PBX order by Name';
              // $result = mysql_query ($query)
              // or die ('Query Failed');
              echo '<form action="setpbx. php" method="POST">' , "\n";
              echo 'Select PBX <select name="pbx">', "\n";
              // while ($row = mysql_fetch_arr ay ($result)) {
              $data = array(array('Na me'=>'FMSite'), array('Name'=>' PG12'));
              foreach ($data as $row) {
              echo '<option value="', $row['Name'], '">', $row['Name'];
              echo "</option>\n";
              }
              echo "</select>\n";
              echo '<input type="submit" value="Submit"> ', "\n";
              echo "</form>\n";

              ?>

              </body>
              </html>

              --
              mail sent to my From: address is publicly readable at www.mailinator.net
              I probably will never read it (possibly some one else will).

              Comment

              • denisb

                #8
                Re: Missing something in passing form variables

                Mike Wilcox <mike.j.wilcox@ intel.com> wrote:[color=blue]
                > The site is on an intranet only and is not accessible from the internet.
                > Here is the HTML source as captured from my browser (IE 6)
                >
                > ***FMSitepbx=FM Site end <form action="setpbx. php" method="POST">
                > Select PBX <select name="pbx"><opt ion value="FMSite"> FMSite<option
                > value="PG12">PG 12</select>
                > <input type="submit" value="Submit"> </form>[/color]

                what happens if you change the name of your <select> ?

                --
                @@@@@
                E -00 comme on est very beaux dis !
                ' `) /
                |\_ =="

                Comment

                • Mike Wilcox

                  #9
                  Re: Missing something in passing form variables

                  Pedro Graca <hexkid@mailina tor.com> wrote in
                  news:slrncp9rd9 .3ru.hexkid@ID-203069.user.uni-berlin.de:
                  [color=blue]
                  > Mike Wilcox wrote:[color=green]
                  >> Here is the HTML source as captured from my browser (IE 6)[/color]
                  >
                  > Your php code, with a few changes, works as expected for me.
                  > Run it on your server:
                  >
                  >
                  > <html>
                  > <head>
                  > <title>xxx</title>
                  > </head>
                  > <body>
                  >
                  > <?php
                  >
                  > error_reporting (E_ALL);
                  > ini_set('displa y_errors', '1');
                  >
                  > echo($_POST['pbx']);
                  >
                  > // $dbcnx = @mysql_connect( "localhost" , "***", "********** ");
                  > // if (!dbcnx) {
                  > // echo "<p>Unable to connect to database.</p>";
                  > // exit();
                  > // }
                  >
                  > // if (!@mysql_select _db("inet")) {
                  > // echo "<p> Unable to locate the iNet database. ", mysql_error(),
                  > "</p>"; // exit();
                  > // }
                  >
                  > // $query = 'Select Name from PBX order by Name';
                  > // $result = mysql_query ($query)
                  > // or die ('Query Failed');
                  > echo '<form action="setpbx. php" method="POST">' , "\n";
                  > echo 'Select PBX <select name="pbx">', "\n";
                  > // while ($row = mysql_fetch_arr ay ($result)) {
                  > $data = array(array('Na me'=>'FMSite'), array('Name'=>' PG12'));
                  > foreach ($data as $row) {
                  > echo '<option value="', $row['Name'], '">', $row['Name'];
                  > echo "</option>\n";
                  > }
                  > echo "</select>\n";
                  > echo '<input type="submit" value="Submit"> ', "\n";
                  > echo "</form>\n";
                  >
                  > ?>
                  >
                  > </body>
                  > </html>
                  >[/color]

                  Pedro,

                  Output is FMSitepbx=FMSit e

                  Thanks,

                  Mike

                  Comment

                  • Mike Wilcox

                    #10
                    Re: Missing something in passing form variables

                    newdb@no-log.org (denisb) wrote in news:1gn5j88.1a d6rqe14y1vooN%n ewdb@no-
                    log.org:
                    [color=blue]
                    > Mike Wilcox <mike.j.wilcox@ intel.com> wrote:[color=green]
                    >> The site is on an intranet only and is not accessible from the internet.
                    >> Here is the HTML source as captured from my browser (IE 6)
                    >>
                    >> ***FMSitepbx=FM Site end <form action="setpbx. php" method="POST">
                    >> Select PBX <select name="pbx"><opt ion value="FMSite"> FMSite<option
                    >> value="PG12">PG 12</select>
                    >> <input type="submit" value="Submit"> </form>[/color]
                    >
                    > what happens if you change the name of your <select> ?
                    >[/color]

                    Changed the name of the <select> to "node" and the echo to $_POST["node"]
                    and now the output is FMSitenode=FMSi te

                    Mike

                    Comment

                    • Ken Robinson

                      #11
                      Re: Missing something in passing form variables


                      Mike Wilcox wrote (in part):[color=blue][color=green]
                      > > what happens if you change the name of your <select> ?
                      > >[/color]
                      >
                      > Changed the name of the <select> to "node" and the echo to[/color]
                      $_POST["node"][color=blue]
                      > and now the output is FMSitenode=FMSi te[/color]

                      Instead of the echo $_POST["node"], try

                      echo '<pre>';print_r ($_POST);echo '</pre>',"\n";

                      Which will show you what's in the $_POST array. That may give you a
                      hint as to what is going on. If the value is correct there, recheck
                      your code.

                      Ken

                      Comment

                      • Pedro Graca

                        #12
                        Re: Missing something in passing form variables

                        Mike Wilcox wrote:[color=blue]
                        > Output is FMSitepbx=FMSit e[/color]
                        ^^^^^^
                        $_POST['pbx']

                        Ah! Maybe I see what is hapenning now :-)

                        Try replacing the "echo($_POS T['pbx']);" at the top of the script with

                        echo $_POST['pbx'], ' *** ';

                        and if the output is

                        FMSite *** pbx=FMSite

                        that proves the $_POST['pbx'] is behaving :-)
                        and that your problem lies elsewhere.



                        To find where is the problem put a few/lot of

                        echo '<p><b>* ', __FILE__, '/', __LINE__, ' *</b></p>';

                        inside your code until you spot the error.
                        --
                        mail sent to my From: address is publicly readable at www.mailinator.net
                        I probably will never read it (possibly some one else will).

                        Comment

                        • denisb

                          #13
                          Re: Missing something in passing form variables

                          Mike Wilcox <mike.j.wilcox@ intel.com> wrote:[color=blue]
                          > newdb@no-log.org (denisb) wrote in news:1gn5j88.1a d6rqe14y1vooN%n ewdb@no-
                          > log.org:[color=green]
                          > > what happens if you change the name of your <select> ?[/color]
                          > Changed the name of the <select> to "node" and the echo to $_POST["node"]
                          > and now the output is FMSitenode=FMSi te[/color]

                          he he...
                          FMSite (the first occurence) is the value expected (in <option...>)
                          node=FMSite is the value sent by the form in his header (name and value
                          of the select element :
                          .. Content-Type: application/x-www-form-urlencoded
                          .. Content-Length: 10
                          .. node=FMSite


                          as Ken said, there is something wrong in your POST array
                          is your Register Globals ON or OFF ?
                          what is your version of php ?

                          is the output (html source) only :
                          FMSitenode=FMSi te<form action...

                          or, as you said in a previous post
                          <Xns959F51B32CB FFmikejwilcoxin telcom@10.7.208 .6> :
                          FMSitenode=FMSi te end <form action...
                          ............... ...^^^^^

                          (funny challenge...)
                          --
                          @@@@@
                          E -00 comme on est very beaux dis !
                          ' `) /
                          |\_ =="

                          Comment

                          • Mike Wilcox

                            #14
                            Re: Missing something in passing form variables

                            "Ken Robinson" <kenrbnsn@rbnsn .com> wrote in
                            news:1100289128 .786992.71380@f 14g2000cwb.goog legroups.com:
                            [color=blue]
                            >
                            > Mike Wilcox wrote (in part):[color=green][color=darkred]
                            >> > what happens if you change the name of your <select> ?
                            >> >[/color]
                            >>
                            >> Changed the name of the <select> to "node" and the echo to[/color]
                            > $_POST["node"][color=green]
                            >> and now the output is FMSitenode=FMSi te[/color]
                            >
                            > Instead of the echo $_POST["node"], try
                            >
                            > echo '<pre>';print_r ($_POST);echo '</pre>',"\n";
                            >
                            > Which will show you what's in the $_POST array. That may give you a
                            > hint as to what is going on. If the value is correct there, recheck
                            > your code.
                            >
                            > Ken
                            >[/color]

                            PHP version is 4.2.2, Apache is 2.0.40.

                            Contents of the array is: [node] => FMSitenode=FMSi te

                            Globals were turned on so I turned them off, no change in the output.

                            Mike

                            Comment

                            • Pedro Graca

                              #15
                              Re: Missing something in passing form variables

                              Mike Wilcox wrote:[color=blue]
                              > PHP version is 4.2.2, Apache is 2.0.40.
                              >
                              > Contents of the array is: [node] => FMSitenode=FMSi te
                              >
                              > Globals were turned on so I turned them off, no change in the output.[/color]

                              Does it also happen with GET method?

                              Try it!
                              change the form method to get and print $_GET['node'].

                              When you POST the GET (lol) what shows up in the address bar of the
                              browser?

                              Are you sure you do only have a single script running?
                              No auto_append_fil e, no auto_prepend_fi le?
                              No user-defined error_handling function set up?
                              --
                              mail sent to my From: address is publicly readable at www.mailinator.net
                              I probably will never read it (possibly some one else will).

                              Comment

                              Working...