Page 5 of 5 First ... 345
  • Jump to page:
    #61
  1. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: $submit, passing form variables to PHP


    there is more info about this problem here: http://www.php.net/release_4_1_0.php (see New Input Mechanism)
  2. #62
  3. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: $submit, passing form variables to PHP


    Mike,

    I look forward to trying this solution. I myself have been looking for it forever. If you are right, you'll be my hero!
  4. #63
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    48
    Rep Power
    17

    Made it work this way...


    Hi,

    Been using PHP for about two days now and most of that time was spent trying to get this cookie.php4 script to work.

    First off, I changed all the '<?' tags to '<?php' and renamed my files from cookie.php4 to cookie.php (no "4" on the end).

    Since I have PHP v.4.2.2, my php.ini config file has this line: 'register_globals = Off'. Because of this, you can't use the straight $variable calls. For example, in the original cookie.php example script, I changed 'if ($day == "Monday")' to 'if ($_GET["day"] == "Monday")' and likewise for the other days.

    In the final combined form/action script, I changed 'switch ($day)' to 'switch ($_GET["day"])' and 'Here is your fortune for <? echo $day; ?>' to 'Here is your fortune for <?php echo $_GET["day"]; ?>' . You get the idea.

    Finally, I figured out that you have to change the intitial 'if (!submit)' statement to 'if (!($_GET["submit"]))' . Then everything worked.

    Here's the whole code I used to make mine work::

    <?php
    if (!($_GET["submit"]))
    {
    // if $submit doesn't exist, it implies that the form
    // has not yet been submitted
    // so display the first page

    ?>

    <html>
    <head>
    <style type="text/css">
    td {font-family: Arial;}
    </style>
    </head>

    <body>
    <BR><BR>
    <font face="Arial" size="+2">
    The Amazing Fortune Cookie Generator
    </font>

    <form method="GET" action="cookie.php">
    <table cellspacing="5" cellpadding="5" border="0">

    <tr>
    <td align="center">
    Pick a day
    </td>
    <td align="right">
    <select name="day">
    <option value="Monday">Monday
    <option value="Tuesday">Tuesday
    <option value="Wednesday">Wednesday
    <option value="Thursday">Thursday
    <option value="Friday">Friday
    <option value="Saturday">Saturday
    <option value="Sunday">Sunday
    </select>
    </td>
    </tr>

    <tr>
    <tr>
    <td colspan="2" align="center">
    <input type="submit" name="submit" value="Hit me!">
    </td>
    </tr>
    </table>
    </form>
    </body>

    </html>


    <?php
    }
    else
    {

    // if $submit does exist, the form has been submitted
    // so process it with switch()

    // the decision variable here is the day chosen by the user
    switch ($_GET["day"])
    {

    // first case
    case "Monday":
    $fortune = "Never make anything simple and efficient when a way can be
    found to make it complex and wonderful.";
    break;

    // second case
    case "Tuesday":
    $fortune = "Life is a game of bridge -- and you've just been
    finessed.";
    break;

    case "Wednesday":
    $fortune = "What sane person could live in this world and not be
    crazy?";
    break;

    case "Thursday":
    $fortune = "Don't get mad, get interest.";
    break;

    case "Friday":
    $fortune = "Just go with the flow control, roll with the crunches,
    and, when you get a prompt, type like hell.";
    break;

    // if none of them match...
    default:
    $fortune = "Sorry, closed on the weekend";
    break;

    }

    ?>

    <html>
    <head>
    <basefont face="Arial">
    </head>

    <body>
    Here is your fortune for <?php echo $_GET["day"]; ?>:
    <br>
    <b><?php echo $fortune; ?></b>

    </body>
    </html>

    <?php
    }

    If, for some reason this is flawed, my apologies.

    Postscript: Getting this comment to display properly using this comment form's structured text formatting was a real byatch! Took a friggin' hour at least :)
  6. #64
  7. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Several buttons on one page each passing a different variable??


    Hi,
    I have created a page with several separate buttons on the page. However I want to be able to assign each button a set variable so that when I go to the next php page the relevant variable will be passed depending on which button was pressed. (eg if i press the submit1 button then i want the variable "1" to be passed but if i click the submit2 button i want the variable "2" to be passed). If anyone knows a way to do this I would be soo grateful,
    Alex.
  8. #65
  9. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: $submit, passing form variables to PHP


    Thanx alot! You saved my day, works fine now.

    /Thomas
  10. #66
  11. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    [no subject]


  12. #67
  13. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    [no subject]


  14. #68
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Albany, NY
    Posts
    1
    Rep Power
    0

    login.php4 form at start of lesson....


    This is not working. Anyone know why? I copied it directly and then tested it. When I type in "bill," that name does not fill into the next page... I've tried submitting the query from both .html and .php file types.
  16. #69
  17. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    login


    Use $_GET['day']
  18. #70
  19. No Profile Picture
    Ducani
    Guest
    Devshed Newbie (0 - 499 posts)

    PHP 101 (Part 2) - Shakespeare's Rose


    PHP 101 \(Part 2\) - Shakespeare\'s Rose

    Now that you've got the basics of PHP variables and operators down, the second article in this series takes a look at PHP's form-processing capabilities, and introduces you to the comparison and logical operators and the "if-else" and "switch" family of conditional statements.

    Please discuss this article in this thread. You can read the article here .
  20. #71
  21. No Profile Picture
    Ducani
    Guest
    Devshed Newbie (0 - 499 posts)
    If you would like to see an article covering a particular topic, please post your request here.
Page 5 of 5 First ... 345
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo