Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    16

    Question Unanswered: Form Help Passing Vars

    I am using the following code:
    <?
    $un = $session->username;
    $my_t=getdate(date("U"));
    ?>
    then
    <?
    echo "<FORM ACTION=process_booking.php METHOD=POST>\n";
    echo "Username : <INPUT TYPE=TEXT NAME=uname VALUE=$un DISABLED=TRUE><BR>\n";
    echo "Booking Date : <INPUT TYPE=TEXT NAME=bdate VALUE=$my_t[year]-$my_t[mon]-$my_t[mday] DISABLED=TRUE><BR>\n";
    echo "<INPUT TYPE=submit value=\"Send the variable\">\n";
    echo "</FORM>\n";
    ?>

    I am passing it to process_booking.php, however in process_booking.php I have a line to check if the two values are being passed:

    echo $_POST['uname']; and
    echo $_POST['bdate'];

    I get no output at all, can anyone spot, or suggest to me why this isn't working?

    Thanks

    Jona

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    <?
    $un = $session->username;
    $my_t=getdate(date("U"));
    ?>
    then
    <?
    echo "<FORM ACTION=process_booking.php METHOD=POST>\n";
    echo "Username : <INPUT TYPE=TEXT NAME=uname VALUE=$un DISABLED=TRUE><BR>\n";
    echo "Booking Date : <INPUT TYPE=TEXT NAME=bdate VALUE=$my_t[year]-$my_t[mon]-$my_t[mday] DISABLED=TRUE><BR>\n";
    echo "<INPUT TYPE=submit value=\"Send the variable\">\n";
    echo "</FORM>\n";
    ?>
    Unless $session is a custom object, you are using sessions incorrectly. Check the docs http://us3.php.net/manual/en/reserve...iables.session.

    Also, using getdate(date("U")) is kind of confusing... Rather, get the timestamp you want, and then use the date() function to format it. I can't test my code, but something like this should be a good start.
    PHP Code:
    <?php

    $un 
    $_SESSION['username'];

    $some_time time();  //or any time
    $formatted_date date('Y-m-d'$some_time);

    ...

    echo 
    "Username : <INPUT TYPE=TEXT NAME=uname VALUE=$un DISABLED=TRUE><BR>\n";
    echo 
    "Booking Date : <INPUT TYPE=TEXT NAME=bdate VALUE=$formatted_date DISABLED=TRUE><BR>\n";

    ?>
    You should probably quote all of the attributes in your input tags as well.

  3. #3
    Join Date
    Mar 2006
    Location
    Copenhagen, Denmark
    Posts
    11
    Quote Originally Posted by jfulton
    You should probably quote all of the attributes in your input tags as well.
    yes, all attributes in the form should be quoted, either by escaping the ("") symbols or by using (''), whereas escaping the quotes is the *safer* option, although it also creates quite untidy code....

    I would do it like this, but i guess it's personal preference really:
    PHP Code:
    <?php

    $un 
    $_SESSION['username'];

    $some_time time();  //or any time
    $formatted_date date('Y-m-d'$some_time); 
    ?>
    then
    PHP Code:
    <? include ('process_booking.php'); ?>
    where process_booking.php is a html-form, and the processing code...
    you could also add functions to check for set cookied before including the process_form, but that's another story....
    Last edited by Krazy^; 04-24-06 at 02:57.

Posting Permissions

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