neophyte
-
Posts
6 -
Joined
-
Last visited
Posts posted by neophyte
-
-
Thanks for your quick reply and answer.
In answer to your request that I clarify "this"...
I could use examples of both: using the code itself and a situation in which headers have already been sent.
I'm just not wrapping my head around this one.
Thanks for your help.
-
Hi Larry,
You include two tips at the end of Chapter 8 that I have questions about.
The first one is:
The headers_sent() function returns TRUE if the page has already received HTTP headers and the header()function can't be used.
Could you please explain an example of this happening.
The second tip is:
Using the GET method trick, you can pass values from one page to another using header():
$var = urlencode('Pass this text');
header ("Location: page.php? message=$var");
When would you want to do this? Please give an example.
THANK YOU for your help!
JJ
-
When I saw that it should just be taxrate++; I changed it to that and it worked. However I just pulled up the file and saw that I'd typed in as taxrate ++; so I'm glad you asked about the space because I hadn't noticed it and I now I can correct that too.
Larry, since you replied to this, I'd just like to thank you for this book! I tried an online "Introduction to PHP" class offered by a local technical college, and spent nearly all of my time completely confused by the teacher's instructions, explanations, and answers. Thank you for breaking this down into understandable bite-sized pieces that I can grasp even though the only 'programming' experience I've had was back in the dark ages of DOS and dBase.
I really can't thank you enough.
Happens to us all. Just to confirm, was the problem the space before the ++ or that the code should actually just be:
$taxrate++;
without assignment?
-
I hate when I find the answer two seconds after I finally break down and ask. I'd struggled with this for a couple of hours and after I posted to this forum I decided to move to the next section of the chapter. That's when I remembered about the scripts. I pulled up the relevent script and almost immediately saw what I'd done wrong.
Thanks anyway!!
-
I'm in Chapter 4 page 84.
The topic is "Incrementing the value of a variable". The instructions are to change $taxrate = $taxrate + 1; to $taxrate = $taxrate++;
I am not getting the right results and I can't figure out why. The code was working before I made this change, and this is the only thing I changed. I've pasted that part of the code with the results below.
I'm using Microsoft Visual Web Developer 2010 Express to write my code, and my browser is IE8: I also tried it in Firefox which was even stranger as you will see below the IE8 results.
Below them all I have pasted the entire code
Thank you for your help
Here is the original (working) code:
//Determine the tax rate
$taxrate = $tax/100;
$taxrate = $taxrate +1;
You have selected to purchase:
10 widget(s) at
$100 price each plus a
$5.00 shipping cost and a
10 % tax rate.
After your $0 discount, the total cost is $1,105.50
Divided over 10 monthly payments, that would be $110.55 each
-------------------------------------------- NOW THE CHANGE TO $taxrate++;
//Determine the tax rate
$taxrate = $tax/100;
$taxrate = $taxrate ++;
You have selected to purchase:
10 widget(s) at
$100 price each plus a
$5.00 shipping cost and a
10 % tax rate.
After your $0 discount, the total cost is $100.50
Divided over 10 monthly payments, that would be $10.05 each
--------------------------------------------
I decided to try it in Firefox and this was my result:
You have selected to purchase:
10 widget(s) at
$10 price each plus a
$5.00 shipping cost and a
10 % tax rate.
After your $10 discount, the total cost is $9.50
Divided over 10 monthly payments, that would be $0.95 each
-----
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Product Cost Calculator</title>
<style type="text/css" media="screen">
.number {font-weight:bold;}
</style>
</head>
<body>
<?php //Script 4.2 - handle_calc.php
/* This script takes values from calculator.html and performs total cost and monthly payment calculations. */
// Address error handling, if you want.
ini_set ('display_errors', 1);
// Get the values from the $_POST array:
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$discount = $_POST['discount'];
$tax = $_POST['tax'];
$shipping = $_POST['shipping'];
$payments = $_POST['payments'];
// Calculate the total:
$total = $price * $quantity;
$total = $total + $shipping;
$total = $total - $discount;
//Determine the tax rate
$taxrate = $tax/100;
$taxrate = $taxrate ++;
//Factor in the tax rate:
$total = $total * $taxrate;
// Calculate the monthly payments:
$monthly =$total / $payments;
//Apply number formatting
$total = number_format ($total, 2);
$monthly = number_format ($monthly, 2);
// Print the results
print "<div><p> You have selected to purchase: <br />
<span class=\"number\">$quantity</span> widget(s) at <br />
$<span class=\"number\">$price </span> price each plus a <br />
$<span class=\"number\">$shipping</span> shipping cost and a<br />
<span class=\"number\">$tax</span> % tax rate. <br />
After your $<span class=\"number\">$discount</span> discount, the total cost is
$<span class=\"number\">$total</span><br />
Divided over <span class=\"number\">$payments</span> monthly payments, that would be $<span class=\"number\">$monthly</span> each
</p>
</div>";
?>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Product Cost Calculator</title>
</head>
<body><!-- Script 4.1 - calculator.html -->
<!--CREATE FORM -->
<div><p>Fill out this form to calculate the total cost:</p>
<form action="handle_calc.php" method="post">
<p>Price: <input type="text" name="price" size="5"</p>
<p>Quantity: <input type="text" name="quantity" size="5"</p>
<p>Discount: <input type="text" name="discount" size="5"</p>
<p>Tax: <input type="text" name="tax" size="3" /> (%)</p>
<!-- SELECT SHIPPING -->
<p>Shipping method: <select name="shipping">
<option value="5.00">Slow and steady</option>
<option value="8.95">Put a move on it!</option>
<option value="19.36">I NEED IT YESTERDAY!</option>
</select></p>
<!--SELECT PAYMENT ARRANGEMENTS -->
<p>Number of payments to make:<input type="text" name="payments" size="3" />
</p>
<input type="submit" name="submit" value="Calculate!" />
</form>
</div>
</body>
</html>
Chapter 9 Creating Cookies P247
in PHP for the Web: Visual QuickStart Guide (3rd Edition)
Posted
Hi Larry,
I am using IE8. I changed my privacy settings to:
'Override automatic cookie handline' and I marked "Prompt" under both First-party and Third-party Cookies.
When I go to any www.'website'.com I get a Privacy Alert message.
But when I run Script 9.1 as http://localhost/view_settings.php, it proceeds with no alerts, warnings, or prompts, and goes right to a page showing my choices.
I tried substituting your script from the downloads, just to find if it was an error in my script, but I got the same results.
(I wanted to try it in FireFox,[version 3.6.17] but I was unable to find the options I needed in the privacy settings tab... )
Any suggestions?
THANKS