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
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post

    unexpected $end??

    hi guys. I have been using dreamweaver to edit php
    this script actually I got it directly from book.
    I was wondering why it always says unexpected $end at the end of the script
    PHP Code:
    <?php 
    $page_title
    ='Calculator'
    //define function calculate total...
    function calculate_total($qty$cost$tax) { 
    $taxrate=$tax/100
    $total=($qty*$cost)*($taxrate+1); 
    echo 
    '<p> The total cost of purchasing '.$qty.' widget(s) at $'.number_format($cost,2).'each, including a tax rate of '.$tax.'% is $'.number_format($total,2).'</p>'
    //form validation...
    if(isset($_POST['submitted'])){ 
        if(
    is_numeric($_POST['quantity'],$_POST['price'],$_POST['tax'])){ // this is not like book, maybe works tho
            //print the heading... 
            
    echo '<h1> Total Cost</h1>'
            
    calculate_total($_POST['quantity'],$_POST['price'],$_POST['tax']); 
            echo 
    '<p><br/></p>'
            } else { 
            echo 
    '<font size=3>Error!</font> <p> Please enter a valid quantity, price and tax</p>'
            }
        }
        
    //end of form validation 
    // leave php and go to html form... 
    ?>

    <h2>Cost Calculator </h2> 
    <form action="calculator.php" method="post">
    <p>Quantity:<input type="text" name="quantity" size="5" maxlength="10" value="<?php if(isset($_POST['quantity']))echo $_POST['quantity']; ?>"/></p>
    <p>Price:<input type="text" name="price" size="5" maxlength="10" value="<?php if(isset($_POST['price']))echo $_POST['price']; ?>"/></p>
    <p>Tax:<input type="text" name="tax" size="5" maxlength="10" value="<?php if(isset($_POST['tax']))echo $_POST[tax]; ?>"/></p>
    <p><input type="submit" name="submit" value="Calculate!"/></p> 
    <p><input type="hidden" name="submitted" value="TRUE"/></p> 
    </form>
    NOTE: it always error at the end
     I deleted some stuff like <html> < head> which have not much effect on script CMIIW

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    1. You never close the function
    PHP Code:
    //define function calculate total...
    function calculate_total($qty$cost$tax) { 
    $taxrate=$tax/100
    $total=($qty*$cost)*($taxrate+1); 
    echo 
    '<p> The total cost of purchasing '.$qty.' widget(s) at $'.number_format($cost,2).'each, including a tax rate of '.$tax.'% is $'.number_format($total,2).'</p>'
    //form validation... 
    a better way:
    PHP Code:
    //define function calculate total...
    function calculate_total($qty$cost$tax) { 
    $taxrate=$tax/100
    $total=($qty*$cost)*($taxrate+1); 
    return 
    '<p> The total cost of purchasing '.$qty.' widget(s) at $'.number_format($cost,2).'each, including a tax rate of '.$tax.'% is $'.number_format($total,2).'</p>'
    }
    //form validation... 
    Then change
    PHP Code:
    calculate_total($_POST['quantity'],$_POST['price'],$_POST['tax']); 
    to
    PHP Code:
    echo calculate_total($_POST['quantity'],$_POST['price'],$_POST['tax']); 
    2.
    PHP Code:
     if(is_numeric($_POST['quantity'],$_POST['price'],$_POST['tax'])){ // this is not like book, maybe works tho 
    no it won't work. should be
    PHP Code:
     if(is_numeric($_POST['quantity']) && is_numeric($_POST['price']) && is_numeric($_POST['tax'])){ // this is not like book, maybe works tho 
    3.
    Code:
     I deleted some stuff like <html> < head> which have not much effect on script
    not a good idea.

    There may be other problems, that was just a quick look.

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post
    oh ? I never close the functioN ?
    I have no clue why it is....
    cause the I typed directly from the book and it won't work... it's a
    "PHP and mysql , for dynamic websites second edition " by larry ulman

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You are also missing a quote here
    Code:
    <p>Tax:<input type="text" name="tax" size="5" maxlength="10" value="<?php if(isset($_POST['tax']))echo $_POST['tax']; ?>"/></p>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post
    oh thanks ..
    but when I run this script , it also says
    PHP Code:
    if(isset($_POST['submitted'])){ 
        if(
    is_numeric($_POST['quantity'])$$is_numberic($_POST['price'])&&is_numberic($_POST['tax'])){ 
    Dont' bother looking back to the first script I posted. cause this one is little modified.


    unexpected end....
    this script makes me pain ...

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    PHP Code:
    if(isset($_POST['submitted'])){ 
        if(
    is_numeric($_POST['quantity']) && is_numberic($_POST['price']) && is_numberic($_POST['tax'])){ 
    You used $$ not && in that snippet. I suggest you pay more attention to what you are typing. These are simple mistakes that shouldn't be happening.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    PHP Code:
    if(isset($_POST['submitted'])){ 
        if(
    is_numeric($_POST['quantity']) && is_numberic($_POST['price']) && is_numberic($_POST['tax'])){ 
    You used $$ not && in that snippet. I suggest you pay more attention to what you are typing. These are simple mistakes that shouldn't be happening.
    aswell as is_numberic isnt a function
    i think you mean is_numeric
    (lol i know you got it right apart from this time)

  • #8
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post
    oh dude.. my bad!..what a damn *** of me Thank you I need to really careful now!!! argh that's why it doesnt work


  •  

    Posting Permissions

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