SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jul 2002
    Location
    Sooner Nation
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IF in form -- Like Dell

    I basically want to add options like you can when building a computer online like Dell I dont want my total to show until you push submit Im not sure Ive done it correctlly becasue the total does show. Am I doing the IF statement correctly?
    PHP Code:
     <?PHP
    $total 
    $single $five;
    if (
    submit == "submit" )
    {

    ?>
    <form action="<?=$PHP_SELF?>"  METHOD="GET">
    <table cellspacing="2" cellpadding="2">
    <tr>
    <td> <input type="radio" name="single" id="" value="85">$85<br>
    <input type="radio" name="single" id="" value="0">no</td>
    <td>Stadard Listing</td>
    </tr>
    <tr>
    <td><input type="radio" name="five" id="" value="45">$45<br>
    <input type="radio" name="five" id="" value="0">no</td></td>
    <td>Add a picture</td>
    </tr>
    </table>
    <input type="submit" value="submit">

    </form>
    <?php
    echo "Total is $total";
    }
    else
    {
    ?>
    <form action="<?=$PHP_SELF?>" method="GET">
    <table cellspacing="2" cellpadding="2">
    <tr>
    <td> <input type="radio" name="single" id="" value="85">$85<br>
    <input type="radio" name="single" id="" value="0">no</td>
    <td>Stadard Listing</td>
    </tr>
    <tr>
    <td><input type="radio" name="single" id="" value="45">$45<br>
    <input type="radio" name="single" id="" value="0">no</td></td>
    <td>Add a picture</td>
    </tr>
    </table>
    <input type="submit" value="submit">

    </form>
    <?php ?>
    Last edited by soonerdm; Mar 30, 2003 at 19:13.
    The only function of business is to create customer value and to innovate. - Peter Drucker

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    if (submit == "submit" )

    should be

    if (isset($_GET['submit']))
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Addict
    Join Date
    Jul 2002
    Location
    Sooner Nation
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by The New Guy
    if (submit == "submit" )

    should be

    if (isset($_GET['submit']))
    Okay I did that but now I dont see the $total after I press submit. I am only seeing the else part no matter what I do?? Any ideas?
    Last edited by soonerdm; Mar 30, 2003 at 19:19.
    The only function of business is to create customer value and to innovate. - Peter Drucker

  4. #4
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You have to get variables that are being posted (or get) by a form by using $_POST (or $_GET).

    So this line $total = $single + $five;

    Should be $total = $_GET['single'] + $_GET['five'];

    There was also a mistake in your form,you had a duplicate "single" input, in your last form.

    Anyway. This should work

    PHP Code:
    <?PHP
    $total 
    $_GET['single'] + $_GET['five'];
    if (
    submit == "submit" )
    {

    ?>
    <form action="<?=$PHP_SELF?>"  METHOD="GET">
    <table cellspacing="2" cellpadding="2">
    <tr>
    <td> <input type="radio" name="single" id="" value="85">$85<br>
    <input type="radio" name="single" id="" value="0">no</td>
    <td>Stadard Listing</td>
    </tr>
    <tr>
    <td><input type="radio" name="five" id="" value="45">$45<br>
    <input type="radio" name="five" id="" value="0">no</td></td>
    <td>Add a picture</td>
    </tr>
    </table>
    <input type="submit" value="submit">

    </form>
    <?php
    echo "Total is $total";
    }
    else
    {
    ?>
    <form action="<?=$PHP_SELF?>" method="GET">
    <table cellspacing="2" cellpadding="2">
    <tr>
    <td> <input type="radio" name="single" id="" value="85">$85<br>
    <input type="radio" name="single" id="" value="0">no</td>
    <td>Stadard Listing</td>
    </tr>
    <tr>
    <td><input type="radio" name="five" id="" value="45">$45<br>
    <input type="radio" name="five" id="" value="0">no</td></td>
    <td>Add a picture</td>
    </tr>
    </table>
    <input type="submit" value="submit">

    </form>
    <?php ?>
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users


Bookmarks

Posting Permissions

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