Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'chapter10'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 2 results

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Cost Calculator</title> </head> <body> <?php // Script 10.4 - calculator.php /* this script displays and handles an HTML form. It uses a function to calculate a total from a quantity and price. */ //this function returns the calculations function calculate_total ($quantity, $price) { $total = $quantity * $price; //calculation $total = number_format ($total, 2); //formatting return $total; //return the value. } //end of calculate_total() function //check for form submisstion if ($_SERVER['REQUEST_METHOD'] == 'POST') { //form validation if (is_numeric($_POST['quantity']) && is_numeric($_POST['price'])) { //call the function and print the results $total = calculate_total($_POST['quantity'], $_POST['price']); print "<p>Your total comes to $<span style=\"font-weight: bold;\">$total.</span></p>"; } else { print '<p style="color: red;">Please make sure to enter only numbers into the calculator.</p>'; } // end of form validation } // end of if checking form has been submitted. ?> <form action="calculator.php" method="POST"> <p>Quantity: <input type="text" name="quantity" size="3" /></p> <p>Price: <input type="text" name="price" size="3" /></p> <p><input type="submit" name="submit" value="Calculate!" /></p> </body> </html> Are variables located inside of functions separate from variables located outside of functions? For example in the above code, the calculate_total() function returns the variable $total. But later on in the script, I assign $total to this: $total = calculate_total($_POST['quantity'], $_POST['price']); By doing that am I overwriting the $total variable? My guess is that the answer is no, because I tried changing the $total variable to something different, for example to $sum, like this: //call the function and print the results $sum = calculate_total($_POST['quantity'], $_POST['price']); print "<p>Your total comes to $<span style=\"font-weight: bold;\">$sum.</span></p>"; and the function still worked properly. I was just looking for a little clarification on this. Thanks. Tim
  2. I am just starting Chapter 10 Pursue #4 now and am still brain storming. Just curious what others came up with? BTW Purse #4 reads: come up with an idea for, create, and use your own custom function. Tim
×
×
  • Create New...