POST, GET and variables ?

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

    #1

    POST, GET and variables ?

    Hello,


    As beginner, I'm a bit confused by passing 2 variables using a html-form
    with method=POST. If passing one of them, it works ; if passing both
    together, nope. At least when I reload the same page by using
    $_SERVER["PHP_SELF"] in an included file (inc.php) it doesn't work.
    Referring to another "page.php" is succesfull. Also passing both variables
    with the GET-method works. Can somebody help me please ?
    Thank you,
    Dirk.
  • Kimmo Laine

    #2
    Re: POST, GET and variables ?

    dirk kirjoitti:
    Hello,
    >
    >
    As beginner, I'm a bit confused by passing 2 variables using a html-form
    with method=POST. If passing one of them, it works ; if passing both
    together, nope. At least when I reload the same page by using
    $_SERVER["PHP_SELF"] in an included file (inc.php) it doesn't work.
    Referring to another "page.php" is succesfull. Also passing both variables
    with the GET-method works. Can somebody help me please ?
    Thank you,
    Dirk.
    Please post some code. The form itself would be quite helpful. What is
    the output of <?php print_r($_POST) ; ?>

    --
    "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
    spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)

    Comment

    • dirk

      #3
      Re: POST, GET and variables ?

      Kimmo Laine wrote:
      >
      Please post some code. The form itself would be quite helpful. What is
      the output of <?php print_r($_POST) ; ?>
      >
      Thanks for your reply. If both input-text-fields were filled in, the
      output of print_r($_POST) is : Array ( )
      If only one input-text-field is filled in, output is : Array ( [email] =>
      mail [pass] =) or Array ( [email] =[pass] =password )
      Here is the code :

      <?php
      $dbh=mysql_conn ect("localhost" ,"user","pas s") or die("Can't connect to
      db!");
      mysql_select_db ("calendar") or die("Can't select db!");
      session_start() ;
      if (!$_SESSION["Login"]) {
      if ($_POST['email'] AND $_POST['pass']) {
      $Email=$_POST['email'];
      $Pass=$_POST['pass'];
      $mydb=mysql_que ry("SELECT ID from admin WHERE Email='$Email'
      and Pass= MD5('$Pass') LIMIT 1");
      if ($data=mysql_fe tch_array($mydb )) {
      $_SESSION["Login"]=$data["ID"];
      }
      $me=$_SERVER['PHP_SELF'];
      header("Locatio n: $me");
      exit;
      }
      print <<<EOL
      <head>
      <title>Admin Console</title>
      </head>
      <body>

      <h1>admin system</h1>
      <form action=
      EOL;
      echo $_SERVER["PHP_SELF"];
      print <<<EOL
      method=post>
      <p>Email<inpu t type=text name=email></p>
      <pPass<input type=password name=pass></p>
      <input type=submit>
      </form></body></html>
      EOL;
      die();

      }
      ?>

      Comment

      • Kimmo Laine

        #4
        Re: POST, GET and variables ?

        dirk kirjoitti:
        Kimmo Laine wrote:
        >
        >Please post some code. The form itself would be quite helpful. What is
        >the output of <?php print_r($_POST) ; ?>
        >>
        Thanks for your reply. If both input-text-fields were filled in, the
        output of print_r($_POST) is : Array ( )
        If only one input-text-field is filled in, output is : Array ( [email] =>
        mail [pass] =) or Array ( [email] =[pass] =password )
        In both cases it should also contain the submit button, I'm guessing it
        defaults to "submit" ="submit" if no values are provided for name and
        value.
        Here is the code :
        >
        <?php
        $dbh=mysql_conn ect("localhost" ,"user","pas s") or die("Can't connect to
        db!");
        mysql_select_db ("calendar") or die("Can't select db!");
        session_start() ;
        if (!$_SESSION["Login"]) {
        if ($_POST['email'] AND $_POST['pass']) {
        $Email=$_POST['email'];
        $Pass=$_POST['pass'];
        $mydb=mysql_que ry("SELECT ID from admin WHERE Email='$Email'
        and Pass= MD5('$Pass') LIMIT 1");
        if ($data=mysql_fe tch_array($mydb )) {
        $_SESSION["Login"]=$data["ID"];
        }
        $me=$_SERVER['PHP_SELF'];
        header("Locatio n: $me");
        exit;
        Should the email and password match and the code reaches this point, the
        post data is lost. Ie. if the login is successful, you'll never see the
        result of the real print_r($_POST) because of the redirection. Humour me
        and run the test case so that a) the login crendentials you input are
        wrong so you don't log in and b) comment the header and exit lines so
        that you are not redirected to another page after successfull login.
        Then see the output.
        }
        print <<<EOL
        <head>
        <title>Admin Console</title>
        </head>
        <body>
        >
        <h1>admin system</h1>
        <form action=
        EOL;
        echo $_SERVER["PHP_SELF"];
        print <<<EOL
        method=post>
        <p>Email<inpu t type=text name=email></p>
        <pPass<input type=password name=pass></p>
        <input type=submit>
        </form></body></html>
        EOL;
        die();
        >
        }
        ?>
        Of course it never hurts to eliminate all other possible causes for
        failure, until you've narrowed it down to the real thing. Hence I
        suggest you clean the code, insert the quotemarks in right places and so on.

        Missing submit from $_POST is quite mysterious. The empty array() can be
        explained if the page is redirected. The test case should be the kind
        where there is absolutely nothing but a form and print_r to make sure
        there isn't anything else causing the data to be lost.

        --
        "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
        spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)

        Comment

        Working...