Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: Simple Php Help

  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple Php Help

    Okay I am taking a PHP class I have the HTML document already I just dont understand the php part well the bold part maybe some one could help Please!

    Create two files (1) an HTML file, and (2) a PHP file. The HTML file should be a form that collects order information on 3 products -- shirts ($10), pants ($20), and shoes ($30). The PHP file should have 7 variables -- shirts, shirtprice, pants, pantprice, shoes, shoeprice, & total. If any customer purchases 3 or more of any item, you should award a 10 percent discount. You must use the conditional statement of your choice to apply the discount. The PHP page must display the information on the browser screen. Also, calculate the grand total cost to the customer.

    The discount is not applied to the total, but to the individual items bought.

    I also attach the html file and the php file I created even though its wrong maybe some one can help me out Thanks!
    Attached Files Attached Files

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    A form is like a contact form that you see on websites ....

    <form action="myphpscript.php" method="post">
    Shoes $20<br>
    How many would you like: <input type="text" name="shoes" value=""><br><br>
    Shirts $25<br>
    How many would you like: <input type="text" name="shirts" value=""><br><br>
    <input type="submit" name="submit" value="Place Order">
    </form>


    Then, it calls a PHP script and the variables are read by the script.
    The PHP script then does the conditional statements and adds things up.

    So, if you search Google for "PHP form processing", you'll get all the
    code you need to read form variables and output a page.

    ... hope that gets you started.

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am confused about the 7 variables I can understand this

    <?php
    echo
    $shirtsprice= 10.00
    $pantsprice=20.00
    $shoesprice=30.00 ?>

    But where do I ge the shirts, pants, shoes, and total varibables from?

    what do I set then equal to? Im lost

    Maybe Im makin this harder than what it is and I have a book but its not helping either

  • #4
    New Coder
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The HTML file will contain the form, which is where the user will input data.

    html file
    ----------------------------------------------------------
    Code:
    <form method="post" action="gotophpfile.php">
     Quantity of Shirts: <input type="text" name="shirts">
     Quantity of Pants: <input type="text" name="pants">
     Quantity of Shoes: <input type="text" name="shoes">
     </form>
    The purpose of creating the PHP file is to interpret the information and return the information with a total cost.

    php file
    ----------------------------------------------------------

    Code:
    <?php
    
    if ($_POST['shirts'] >= 3 || $_POST['pants'] >=3 || $_POST['shoes'] >=3)
    {
     $discountMult = .9;
    }
    else { $discountMult = 1; }
    
     $total = (($_POST['shirts'] * $shirtsPrice) + 
                 ($_POST['pants'] * $pantsPrice) +
                 ($_POST['shoes'] * $shoesPrice)) * $discountMult;
    
    echo "
     Shirts: " . $_POST['shirts'] . "x Price: " . $shirtsPrice . " <br>
     Pants: " . $_POST['pants'] . "x Price: " . $pantsPrice . " <br>
     Shoes: " . $_POST['shoes'] . "x Price: " . $shoesPrice . " <br>
     Total: " . $total . " <br>
           ";
    
    ?>
    I did this in a hurry so if there are some errors let me know, but that's pretty much what you want.

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    PB ...

    This is really homework and we shouldn't give you the answers.

    Why isn't your teacher showing you this basic HTML/PHP stuff?

    That is a really poor reflection on your instructor.

    Everything we're showing you is like HTML 101 ..
    If you search Google, you'll find tutorials that show you exactly what to do.
    If you're paying for this class, I'd ask for my money back.

  • #6
    New Coder
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I guess it was wrong of me to post your homework lol, but I will say this...

    This assignment does seem kind of confusing and not perfectly clear, i don't know if this was the exact assignment or a paraphrase but the assignment is very unclear and does reflect badly on your professor.

  • #7
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Im mean I know how to create the HTML I just didn't understand the PHP Im new at this and the class I am taking is a Online class so I can ask him but it will take him forever to email me back........ so I just decided to come here


    but I have another quetion where does the prices of the shirts, pants, shoes come in at (like the 10.00, 20.00, 30.00)


    I don't work well just reading the book... I have to ask question

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    You can include the prices within your form as
    hidden variables, but that is a security risk,
    so define the prices directly inside your PHP script.

    <?php

    $shirts_qty="$_POST['shirts'];
    $shirts_cost=20;

    $shoes_qty="$_POST['shoes'];
    $shoes_cost=30;

    $total=($shirts_qty*$shirts_cost)+($shoes_qty*$shoes_cost);

    echo $total;
    ?>


  •  

    Posting Permissions

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