I am new to this forum and I help some help. I’m doing a class project. If someone could help me finish it up would be appreciated. I am completely lost now.
Professors instructions
In the summary page I need to show
A. The number of rentals entered
B. Total Amount of all rentals entered
C. Percentage of rentals which were high end models (luxury, minivan, suv)
D. Percentage of rentals selected as least one “extra – dvd ,cd, satellite ,GPS.
My php script so far:
<?php
session_start();
if (!(isset($_POST[‘first_time’]))) {
$
$_SESSION[‘fin’] = 0;
}
if (isset($_POST[‘submit’])) {
// Address error handling
// Get the values from the $_POST array:
$firstname=$
$lastname=$_POST[‘lastname’];
$deposit=$
$days=$_POST[‘days’];
$beginningmileage=$
$endmileage=$_POST[‘endmileage’];
$ins=$
$discount=$_POST[‘discount’];
$drivers=$
$model=$_POST[‘model’];
$under25=$
$gastank=$_POST[‘gas’];
$gallons=$
$features=$_POST[‘features’];
// Validate the firstname
if(empty($_POST[‘firstname’])) {
print ‘<p> Please enter your first name.</p>’;
$okay= FALSE;
}
// Validate the lastname
if(empty($
print ‘<p> Please enter your last name.</p>’;
$okay= FALSE;
}
// Validate the days
if (is_numeric($_POST[‘days’])) {
//Check that days is greater then 0.
if ($_POST[‘days’]< 1) {
print ‘<p> You must enter days greater then 0</p>’;
$okay= FALSE;
}
}
else {
print ‘<p> Number of days are not numeric</p>’;
$okay= FALSE;
}
//Calculate the total:
$daily= $model* $days;
$mileage= ($endmileage-$beginningmileage-($days*.35;
if ($mileage<0)
$mileage=0;
$drivers=($drivers-1)*$days;
$sub= $daily+$mileage+$drivers+features;
$coverage=$sub*$ins;
$tax= $sub
$tot=0;
foreach ($features as $charge){
$tot=$tot+$charge;
}
$extra=$tot*$days;
$fin=$sub+$coverage+$tax+$extra-$deposit;
$fin=$fin-($fin*$discount);
$daily=number_format($daily,2);
print “daily:$$daily<br/>”;
$mileage=number_format($mileage,2);
print “mileage:$$mileage<br/>”;
/
*/
$drivers=number_format($drivers,2);
print “drivers:$$drivers<br/>”;
$underdrivers=$under25
if ($gastank==”E”){
$gascharge=$gallons*3;}
else{$gascharge=$gallons
$sub=number_format($sub,2);
print “extra:$$extra<br/>”;
print “discount:$discount<br/>”;
print “sub:$$sub<br/>”;
$coverage=number_format($coverage,2);
print “coverage:$$coverage<br/>”;
$fin=number_format($fin,2);
print “fin:$$fin<br/>”;
$_SESSION[‘cnt’] = $
$_SESSION[‘fin’] = $
print ‘<form method=”post” action=”Test2.php”>
<p><input name=”rentals” value=”Enter New Rental” type=”submit”></p>
<p><input name=”finish” value=”Complete All Rentals” type=”submit”></p>
<input type=”hidden” name=”first_time” value=”true”>
</form>’;
}
else
{
if (isset($_POST[‘finish’])) {
print “summary form here is the count ” . $
print “total amount of all rentals” . $_SESSION[‘fin’];
}
else {
?>
<!DOCTYPE html
<head>
</head>
<body>
<div><p>Complete this form for rates:</p>
<form action=”” method=”post”>
<php?
<p>First Name: <input type=”text” name=”firstname” size=”20″ /></p>
<p>Last Name: <input type=”text” name=”lastname” size=”20″ /></p>
<p>Initial Deposit: <input type=”text” name=”deposit” size=”20″ /></p>
<p>Number of Days Rental: <input type=”text” name=”days” size=”3″ /></p>
<p>Beginning Mileage: <input type=”text” name=”beginningmileage” size=”10″ /></p>
<p>Ending Mileage: <input type=”text” name=”endmileage” size=”10″ /></p>
<p>Insurance: <select name=”coverage”>
<option value=”1″>Yes</option>
<option value=”0″>No</option>
</select></p>
<p>Customer Type;
<select name=”discount”>
<option value=”0″>Retail</option>
<option value=”.1″>Preferred</option>
<option value=”.15 “>Corporate</option>
<select></p>
<p>Number of Drivers: <select name=”drivers”>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
</select></p>
<p>Choose Model: <select name=”model”>
<option value=”20″>Subcompact</option>
<option value=”25″>Compact</option>
<option value=”30″>Mid-Size</option>
<option value=”40″>Luxury</option>
<option value=”80″>Minivan</option>
<option value=”60″>SUV</option>
</select></p>
<p>Under 25?: <select name=”age”>
<option value=”0″>0</option>
<option value=”2.50″>1</option>
<option value=”5.00″>2</option>
<option value=”7.50″>3</option>
</select></p>
<p>Gas tank: <select name=”gas”>
<option value=”E”>Bring it empty</option>
<option value=”F”>Bring it full</option>
<p>Number gallons: <input type=”text” name=”gallons” size=”3″ /></p>
<input type=”hidden” name=”first_time” value=”true”>
<p> Extra Features;
<input type=”checkbox” name=”features[]” value=”5.00″/>DVD Player
<input type=”checkbox” name=”features[]” value=”10.00″/>Multi-CD/MP3 Player
<input type=”checkbox” name=”features[]” value=”3.00″/>Satellite Radio
<input type=”checkbox” name=”features[]” value=”5.00″/>GPS
<input type=”submit” name=”submit” value=”Submit Form” />
?>
</form>
</div>
</body>
</html>
<?php
}
}
?>
Thanks for any help.
[code=php]
<?php
session_start();
if (!(isset($_POST['first_time']))) {
$_SESSION['cnt'] = 0;
$_SESSION['fin'] = 0;
}
if (isset($_POST['submit'])) {
// Address error handling
// Get the values from the $_POST array:
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$deposit=$_POST['deposit'];
$days=$_POST['days'];
$beginningmileage=$_POST['beginningmileage'];
$endmileage=$_POST['endmileage'];
$ins=$_POST['coverage'];
$discount=$_POST['discount'];
$drivers=$_POST['drivers'];
$model=$_POST['model'];
$under25=$_POST['age'];
$gastank=$_POST['gas'];
$gallons=$_POST['galllons'];
$features=$_POST['features'];
// Validate the firstname
if(empty($_POST['firstname'])) {
print '<p> Please enter your first name.</p>';
$okay= FALSE;
}
// Validate the lastname
if(empty($_POST['lastname'])) {
print '<p> Please enter your last name.</p>';
$okay= FALSE;
}
// Validate the days
if (is_numeric($_POST['days'])) {
//Check that days is greater then 0.
if ($_POST['days']< 1) {
print '<p> You must enter days greater then 0</p>';
$okay= FALSE;
}
}
else {
print '<p> Number of days are not numeric</p>';
$okay= FALSE;
}
//Calculate the total:
$daily= $model* $days;
$mileage= ($endmileage-$beginningmileage-($days*100))*.35;
if ($mileage<0)
$mileage=0;
$drivers=($drivers-1)*5*$days;
$sub= $daily+$mileage+$drivers+features;
$coverage=$sub*.1*$ins;
$tax= $sub *0.05;
$tot=0;
foreach ($features as $charge){
$tot=$tot+$charge;
}
$extra=$tot*$days;
$fin=$sub+$coverage+$tax+$extra-$deposit;
$fin=$fin-($fin*$discount);
$daily=number_format($daily,2);
print "daily:$$daily<br/>";
$mileage=number_format($mileage,2);
print "mileage:$$mileage<br/>";
/*print "mileage chargeprin:<br/>
*/
$drivers=number_format($drivers,2);
print "drivers:$$drivers<br/>";
$underdrivers=$under25*$days;
if ($gastank=="E"){
$gascharge=$gallons*3;}
else{$gascharge=$gallons*3;}
$sub=number_format($sub,2);
print "extra:$$extra<br/>";
print "discount:$discount<br/>";
print "sub:$$sub<br/>";
$coverage=number_format($coverage,2);
print "coverage:$$coverage<br/>";
$fin=number_format($fin,2);
print "fin:$$fin<br/>";
$_SESSION['cnt'] = $_SESSION['cnt'] + 1;
$_SESSION['fin'] = $_SESSION['fin'] + $fin;
print '<form method="post" action="Test2.php">
<p><input name="rentals" value="Enter New Rental" type="submit"></p>
<p><input name="finish" value="Complete All Rentals" type="submit"></p>
<input type="hidden" name="first_time" value="true">
</form>';
}
else
{
if (isset($_POST['finish'])) {
print "summary form here is the count " . $_SESSION['cnt'];
print "total amount of all rentals" . $_SESSION['fin'];
}
else {
?>
[/code]
[code=php]
<!DOCTYPE html
<head>
</head>
<body>
<div><p>Complete this form for rates:</p>
<form action="" method="post">
<php?
<p>First Name: <input type="text" name="firstname" size="20" /></p>
<p>Last Name: <input type="text" name="lastname" size="20" /></p>
<p>Initial Deposit: <input type="text" name="deposit" size="20" /></p>
<p>Number of Days Rental: <input type="text" name="days" size="3" /></p>
<p>Beginning Mileage: <input type="text" name="beginningmileage" size="10" /></p>
<p>Ending Mileage: <input type="text" name="endmileage" size="10" /></p>
<p>Insurance: <select name="coverage">
<option value="1">Yes</option>
<option value="0">No</option>
</select></p>
<p>Customer Type;
<select name="discount">
<option value="0">Retail</option>
<option value=".1">Preferred</option>
<option value=".15 ">Corporate</option>
<select></p>
<p>Number of Drivers: <select name="drivers">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
</select></p>
<p>Choose Model: <select name="model">
<option value="20">Subcompact</option>
<option value="25">Compact</option>
<option value="30">Mid-Size</option>
<option value="40">Luxury</option>
<option value="80">Minivan</option>
<option value="60">SUV</option>
</select></p>
<p>Under 25?: <select name="age">
<option value="0">0</option>
<option value="2.50">1</option>
<option value="5.00">2</option>
<option value="7.50">3</option>
</select></p>
<p>Gas tank: <select name="gas">
<option value="E">Bring it empty</option>
<option value="F">Bring it full</option>
<p>Number gallons: <input type="text" name="gallons" size="3" /></p>
<input type="hidden" name="first_time" value="true">
<p> Extra Features;
<input type="checkbox" name="features[]" value="5.00"/>DVD Player
<input type="checkbox" name="features[]" value="10.00"/>Multi-CD/MP3 Player
<input type="checkbox" name="features[]" value="3.00"/>Satellite Radio
<input type="checkbox" name="features[]" value="5.00"/>GPS
<input type="submit" name="submit" value="Submit Form" />
?>
</form>
</div>
</body>
</html>
<?php
}
}
?>
[/code]
what problem are you having exactly? also in future (as your new you may not have known) use [ php ] code here [ /php ] without space's inside the brackets.
it also help make debugging easier.
NO CHANGE MADE JUST FOR BETTER VIEWING
[code=php]
<?php
session_start();
if (!(isset($_POST['first_time']))) {
$_SESSION['cnt'] = 0;
$_SESSION['fin'] = 0;
}
if (isset($_POST['submit'])) {
// Address error handling
// Get the values from the $_POST array:
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$deposit=$_POST['deposit'];
$days=$_POST['days'];
$beginningmileage=$_POST['beginningmileage'];
$endmileage=$_POST['endmileage'];
$ins=$_POST['coverage'];
$discount=$_POST['discount'];
$drivers=$_POST['drivers'];
$model=$_POST['model'];
$under25=$_POST['age'];
$gastank=$_POST['gas'];
$gallons=$_POST['galllons'];
$features=$_POST['features'];
// Validate the firstname
if(empty($_POST['firstname'])) {
print '<p> Please enter your first name.</p>';
$okay= FALSE;
}
// Validate the lastname
if(empty($_POST['lastname'])) {
print '<p> Please enter your last name.</p>';
$okay= FALSE;
}
// Validate the days
if (is_numeric($_POST['days'])) {
//Check that days is greater then 0.
if ($_POST['days']< 1) {
print '<p> You must enter days greater then 0</p>';
$okay= FALSE;
}
}
else {
print '<p> Number of days are not numeric</p>';
$okay= FALSE;
}
//Calculate the total:
$daily= $model* $days;
$mileage= ($endmileage-$beginningmileage-($days*100))*.35;
if ($mileage<0)
$mileage=0;
$drivers=($drivers-1)*5*$days;
$sub= $daily+$mileage+$drivers+features;
$coverage=$sub*.1*$ins;
$tax= $sub *0.05;
$tot=0;
foreach ($features as $charge){
$tot=$tot+$charge;
}
$extra=$tot*$days;
$fin=$sub+$coverage+$tax+$extra-$deposit;
$fin=$fin-($fin*$discount);
$daily=number_format($daily,2);
print "daily:$$daily<br/>";
$mileage=number_format($mileage,2);
print "mileage:$$mileage<br/>";
/*print "mileage chargeprin:<br/>
*/
$drivers=number_format($drivers,2);
print "drivers:$$drivers<br/>";
$underdrivers=$under25*$days;
if ($gastank=="E"){
$gascharge=$gallons*3;}
else{$gascharge=$gallons*3;}
$sub=number_format($sub,2);
print "extra:$$extra<br/>";
print "discount:$discount<br/>";
print "sub:$$sub<br/>";
$coverage=number_format($coverage,2);
print "coverage:$$coverage<br/>";
$fin=number_format($fin,2);
print "fin:$$fin<br/>";
$_SESSION['cnt'] = $_SESSION['cnt'] + 1;
$_SESSION['fin'] = $_SESSION['fin'] + $fin;
print '<form method="post" action="Test2.php">
<p><input name="rentals" value="Enter New Rental" type="submit"></p>
<p><input name="finish" value="Complete All Rentals" type="submit"></p>
<input type="hidden" name="first_time" value="true">
</form>';
}
else
{
if (isset($_POST['finish'])) {
print "summary form here is the count " . $_SESSION['cnt'];
print "total amount of all rentals" . $_SESSION['fin'];
}
else {
?>
[/code]
[code=php]
<!DOCTYPE html
<head>
</head>
<body>
<div><p>Complete this form for rates:</p>
<form action="" method="post">
<php?
<p>First Name: <input type="text" name="firstname" size="20" /></p>
<p>Last Name: <input type="text" name="lastname" size="20" /></p>
<p>Initial Deposit: <input type="text" name="deposit" size="20" /></p>
<p>Number of Days Rental: <input type="text" name="days" size="3" /></p>
<p>Beginning Mileage: <input type="text" name="beginningmileage" size="10" /></p>
<p>Ending Mileage: <input type="text" name="endmileage" size="10" /></p>
<p>Insurance: <select name="coverage">
<option value="1">Yes</option>
<option value="0">No</option>
</select></p>
<p>Customer Type;
<select name="discount">
<option value="0">Retail</option>
<option value=".1">Preferred</option>
<option value=".15 ">Corporate</option>
<select></p>
<p>Number of Drivers: <select name="drivers">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
</select></p>
<p>Choose Model: <select name="model">
<option value="20">Subcompact</option>
<option value="25">Compact</option>
<option value="30">Mid-Size</option>
<option value="40">Luxury</option>
<option value="80">Minivan</option>
<option value="60">SUV</option>
</select></p>
<p>Under 25?: <select name="age">
<option value="0">0</option>
<option value="2.50">1</option>
<option value="5.00">2</option>
<option value="7.50">3</option>
</select></p>
<p>Gas tank: <select name="gas">
<option value="E">Bring it empty</option>
<option value="F">Bring it full</option>
<p>Number gallons: <input type="text" name="gallons" size="3" /></p>
<input type="hidden" name="first_time" value="true">
<p> Extra Features;
<input type="checkbox" name="features[]" value="5.00"/>DVD Player
<input type="checkbox" name="features[]" value="10.00"/>Multi-CD/MP3 Player
<input type="checkbox" name="features[]" value="3.00"/>Satellite Radio
<input type="checkbox" name="features[]" value="5.00"/>GPS
<input type="submit" name="submit" value="Submit Form" />
?>
</form>
</div>
</body>
</html>
<?php
}
}
?>
[/code]
hopefully we will be able to help you.[/QUOTE]
Yes - with ALL this code it would be nice if you told us what you were looking for....[/QUOTE]
In the simplest sense, calculate it in php and then echo out the value with some text id'ing it. No? Or it the problem more complex than "How to add % to my summary page"?[/QUOTE]
Since this is an assignment, I'm not going to write your code for you. You attempt it and let us see it. You've written all this other code (haven't you?) so what's the specific problem with this one little line of code?[/QUOTE]
Since you apparently have not LEARNED any php while copying the code from a book, you are dead set on cheating to get you class assignment done. Did you ever hear of google? BTW - have you run the existing code to see that IT works correctly?[/QUOTE]
[code=php]
$gallons = $_POST['galllons']; // 3 L's in gallons around line 27
[/code]
[code=php]
$sub = $daily + $mileage + $drivers+features; //features is not a variable around line 59
[/code]
[code=php]
<php? // not sure why this is here around line 123
[/code]
[code=php]
enctype="multipart/form-data"
[/code]
[code=php]
$firstname = $_POST['firstname'];
//instead use the isset or empty to initialize the variable
$firstname = isset($_POST['firstname']) ? $_POST['firstname'] : null; //isset
$firstname = empty($_POST['firstname']) ? null : $_POST['firstname'];
[/code]
First not sure how you Professor feels about standards and best practices but there are a fair few that you should really address.
a few mistakes i have noticed at a cursory glance.
[code=php]
$gallons = $_POST['galllons']; // 3 L's in gallons around line 27
[/code]
[code=php]
$sub = $daily + $mileage + $drivers+features; //features is not a variable around line 59
[/code]
[code=php]
<php? // not sure why this is here around line 123
[/code]
and mistakes / bad practices
if using checkboxes with array value names use
[code=php]
enctype="multipart/form-data"
[/code]
if values are empty you will get Notice: Undefined index:
[code=php]
$firstname = $_POST['firstname'];
//instead use the isset or empty to initialize the variable
$firstname = isset($_POST['firstname']) ? $_POST['firstname'] : null; //isset
$firstname = empty($_POST['firstname']) ? null : $_POST['firstname'];
[/code]
As for the assignment I can't(won't) help without knowing the exact error or problem you are having sorry.[/QUOTE]
<!DOCTYPE html[COLOR="#FF0000"]>[/COLOR]
<option value=[COLOR="#FF0000"]"[/COLOR]1[COLOR="#FF0000"]"[/COLOR]>1</option>
<option value=[COLOR="#FF0000"]"[/COLOR]2[COLOR="#FF0000"]"[/COLOR]>2</option>
<option value=[COLOR="#FF0000"]"[/COLOR]3[COLOR="#FF0000"]"[/COLOR]>3</option>
<option value=[COLOR="#FF0000"]"[/COLOR]4[COLOR="#FF0000"]"[/COLOR]>4</option>
<option value=[COLOR="#FF0000"]"[/COLOR]5[COLOR="#FF0000"]"[/COLOR]>5</option>
<option value=[COLOR="#FF0000"]"[/COLOR]6[COLOR="#FF0000"]"[/COLOR]>6</option>
<option value=[COLOR="#FF0000"]"[/COLOR]7[COLOR="#FF0000"]"[/COLOR]>7</option>
<option value=[COLOR="#FF0000"]"[/COLOR]8[COLOR="#FF0000"]"[/COLOR]>8</option>
$_SESSION['cnt'] = $_SESSION['cnt'] + 1;
$_SESSION['fin'] = $_SESSION['fin'] + $fin;
[COLOR="#FF0000"]$_SESSION['entry' . $_SESSION['cnt']] = array(
<i> </i>'model' => $model,
<i> </i>'features' => $features
);[/COLOR]
Array
(
[cnt] => 3
[fin] => 2986.95
[entry1] => Array
(
[model] => 30
[features] => Array
(
[0] => 10.00
[1] => 3.00
)
<i> </i> )
<i> </i>[entry2] => Array
<i> </i> (
<i> </i> [model] => 30
<i> </i> [features] => Array
<i> </i> (
<i> </i> [0] => 10.00
<i> </i> [1] => 3.00
<i> </i> )
<i> </i> )
<i> </i>[entry3] => Array
<i> </i> (
<i> </i> [model] => 30
<i> </i> [features] => Array
<i> </i> (
<i> </i> [0] => 10.00
<i> </i> [1] => 3.00
<i> </i> )
<i> </i> )
)
Additional corrections to be mentioned:
[B]Line 116:[/B] (missing bracket)
<!DOCTYPE html[COLOR="#FF0000"]>[/COLOR]
[B]Line 143+[/B] (unquoted attributes)
<option value=[COLOR="#FF0000"]"[/COLOR]1[COLOR="#FF0000"]"[/COLOR]>1</option>
<option value=[COLOR="#FF0000"]"[/COLOR]2[COLOR="#FF0000"]"[/COLOR]>2</option>
<option value=[COLOR="#FF0000"]"[/COLOR]3[COLOR="#FF0000"]"[/COLOR]>3</option>
<option value=[COLOR="#FF0000"]"[/COLOR]4[COLOR="#FF0000"]"[/COLOR]>4</option>
<option value=[COLOR="#FF0000"]"[/COLOR]5[COLOR="#FF0000"]"[/COLOR]>5</option>
<option value=[COLOR="#FF0000"]"[/COLOR]6[COLOR="#FF0000"]"[/COLOR]>6</option>
<option value=[COLOR="#FF0000"]"[/COLOR]7[COLOR="#FF0000"]"[/COLOR]>7</option>
<option value=[COLOR="#FF0000"]"[/COLOR]8[COLOR="#FF0000"]"[/COLOR]>8</option>
In regards to the summary information, you will need to collect more data in order to generate a report from. As you are already using the session to store the amount of entries, why not just store specific entry data as well.
[B]For example (Line 94):[/B]
$_SESSION['cnt'] = $_SESSION['cnt'] + 1;
$_SESSION['fin'] = $_SESSION['fin'] + $fin;
[COLOR="#FF0000"]$_SESSION['entry' . $_SESSION['cnt']] = array(
<i> </i>'model' => $model,
<i> </i>'features' => $features
);[/COLOR]
After a few submission your session data would end up like this (using[COLOR="#008000"][FONT=Courier New]print_r($_SESSION);[/FONT][/COLOR] ):
Array
(
[cnt] => 3
[fin] => 2986.95
[entry1] => Array
(
[model] => 30
[features] => Array
(
[0] => 10.00
[1] => 3.00
)
<i> </i> )
<i> </i>[entry2] => Array
<i> </i> (
<i> </i> [model] => 30
<i> </i> [features] => Array
<i> </i> (
<i> </i> [0] => 10.00
<i> </i> [1] => 3.00
<i> </i> )
<i> </i> )
<i> </i>[entry3] => Array
<i> </i> (
<i> </i> [model] => 30
<i> </i> [features] => Array
<i> </i> (
<i> </i> [0] => 10.00
<i> </i> [1] => 3.00
<i> </i> )
<i> </i> )
)
You could then loop through the data at a later stage and sum it up.[/QUOTE]
for ($i = 1; $i <= $_SESSION['cnt']; ++$i) {
<i> </i>echo 'Entry ' . $i . ' = ' . $_SESSION['entry' . $i]['model'] . ' / ' . count($_SESSION['entry' . $i]['features']) . '<br />';
}
Entry 1 = 30 / 2
Entry 2 = 30 / 2
Entry 3 = 30 / 2[/QUOTE]
[FONT=Courier New]print_r[/FONT] is a function that displays the contents of a variable. You can refer to it here:http://www.php.net/print_r
The actual summary work will need to be done using a loop if you decide to use the recommendation above, for example:
for ($i = 1; $i <= $_SESSION['cnt']; ++$i) {
<i> </i>echo 'Entry ' . $i . ' = ' . $_SESSION['entry' . $i]['model'] . ' / ' . count($_SESSION['entry' . $i]['features']) . '<br />';
}
Output Example (data dependant):[/QUOTE]
I was beat to the punch!
Judging by the number of replies to your statement 'it runs perfect' I can see that you are not telling the truth.
Merry Xmas - and I suggest dropping this course since you didn't learn anything.[/QUOTE]
A. The number of rentals entered
you have done this.
As for the next 3 I don't understand how you want this to work as sessions are only alive for the life of the browser window being open.
B. Total Amount of all rentals entered
C. Percentage of rentals which were high end models (luxury, minivan, suv)
D. Percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS.
Once you close the browser is closed all session data will be lost.
Also you seem to asking a math question, not so much a code problem.
As a mathematical issue to get the percentage divide by 100
Whilst it may seem that we are being unhelpful it should be understood that most of us want the people we help to learn and hopefully discover the solution themselves especially when their question is based on a assignment.[/QUOTE]
I'm curious to know when this is due, I thought most places had already closed for the holidays?[/QUOTE]
I'm curious to know when this is due, I thought most places had already closed for the holidays?[/QUOTE]
OK, then how are you coming along? Do you have what you need to complete it now?[/QUOTE]
//Check that days is greater then 0.
if ($_POST['days']< 1) {
print '<p> You must enter days greater then 0</p>';
$okay= FALSE;
}
}
else {
I see that ? there are still some of the previously mentioned issues outstanding in this submission. Let me look through it...[/QUOTE]
<?php
<i> </i>session_start();
<i> </i>if (!(isset($_POST['first_time']))) {
<i> </i> $_SESSION['cnt'] = 0;
<i> </i> $_SESSION['fin'] = 0;
<i> </i>}
<i> </i>if (isset($_POST['submit'])) { //TODO: Address error handling
<i> </i> // Get the values from the $_POST array:
<i> </i> $firstname = $_POST['firstname'];
<i> </i> $lastname = $_POST['lastname'];
<i> </i> $deposit = $_POST['deposit'];
<i> </i> $days = (int)$_POST['days'];
<i> </i> $beginningmileage = (int)$_POST['beginningmileage'];
<i> </i> $endmileage = (int)$_POST['endmileage'];
<i> </i> $ins = $_POST['coverage'];
<i> </i> $discount = $_POST['discount'];
<i> </i> $drivers = $_POST['drivers'];
<i> </i> $model = (int)$_POST['model'];
<i> </i> $under25 = $_POST['age'];
<i> </i> $gastank = $_POST['gas'];
<i> </i> $gallons = $_POST['gallons'];
<i> </i> $features = isset($_POST['features']) ? $_POST['features'] : array();
<i> </i> $okay = true;
<i> </i> // Validate the firstname
<i> </i> if(!$firstname) {echo '<p> Please enter your first name.</p>'; $okay = false;}
<i> </i> // Validate the lastname
<i> </i> if(!$lastname) {echo '<p> Please enter your last name.</p>'; $okay = false;}
<i> </i> //Check that days is greater then 0.
<i> </i> if (!$days) {echo '<p> You must enter days greater then 0</p>'; $okay = false;}
<i> </i> //Calculate the total:
<i> </i> $daily = $model * $days;
<i> </i> $mileage = ($endmileage - $beginningmileage - ($days * 100)) * .35;
<i> </i> if ($mileage < 0) {$mileage = 0;}
<i> </i> $drivers = ($drivers - 1) * 5 * $days;
<i> </i> $sub = $daily + $mileage + $drivers; // + $features;
<i> </i> $coverage = $sub * .1 * $ins;
<i> </i> $tax = $sub * 0.05;
<i> </i> $tot = 0;
<i> </i> foreach ($features as $charge) {
<i> </i> $tot = $tot + $charge;
<i> </i> }
<i> </i> $extra = $tot * $days;
<i> </i> $fin = $sub + $coverage + $tax + $extra - $deposit;
<i> </i> $fin = $fin - ($fin * $discount);
<i> </i> $daily = number_format($daily, 2);
<i> </i> echo "daily:$$daily<br />";
<i> </i> $mileage = number_format($mileage, 2);
<i> </i> echo 'mileage:$$mileage<br />';
<i> </i> /*print "mileage chargeprin:<br/>
<i> </i> */
<i> </i> $drivers = number_format($drivers, 2);
<i> </i> echo "drivers:$$drivers<br />";
<i> </i> $underdrivers = $under25 * $days;
<i> </i> if ($gastank == 'E') {$gascharge = $gallons * 3;} else
<i> </i> {$gascharge = $gallons * 3;}
<i> </i> $sub = number_format($sub, 2);
<i> </i> echo "extra:$$extra<br />";
<i> </i> echo "discount:$discount<br />";
<i> </i> echo "sub:$$sub<br />";
<i> </i> $coverage = number_format($coverage, 2);
<i> </i> echo "coverage:$$coverage<br />";
<i> </i> $fin = number_format($fin, 2);
<i> </i> echo "fin:$$fin<br />";
<i> </i> $_SESSION['cnt'] = $_SESSION['cnt'] + 1;
<i> </i> $_SESSION['fin'] = $_SESSION['fin'] + $fin;
<i> </i> $_SESSION['entry' . $_SESSION['cnt']] = array(
<i> </i> 'model' => $model,
<i> </i> 'features' => $features
<i> </i> );
<i> </i> echo
<i> </i> '<form method="post" action="">
<i> </i> <p><input name="rentals" value="Enter New Rental" type="submit"></p>
<i> </i> <p><input name="finish" value="Complete All Rentals" type="submit"></p>
<i> </i> <input type="hidden" name="first_time" value="true">
<i> </i> </form>';
<i> </i>} else
<i> </i>if (isset($_POST['finish'])) {
<i> </i> $rentals_high = 0;
<i> </i> $rentals_feature = 0;
<i> </i> for ($i = 1; $i <= $_SESSION['cnt']; ++$i) {$j = $_SESSION['entry' . $i];
<i> </i> //Percentage of rentals which were high end models (luxury, minivan, suv)
<i> </i> if ($j['model'] > 30) {$rentals_high++;}
<i> </i> //Percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS.
<i> </i> if (count($j['features'])) {$rentals_feature++;}
<i> </i> }
<i> </i> echo
<i> </i> 'Summary Form<br />' .
<i> </i> 'Here is the count ' . $_SESSION['cnt'] . '<br />' .
<i> </i> 'Total amount of all rentals ' . $_SESSION['fin'] . '<br />' .
<i> </i> 'Percentage of high end models ' . $rentals_high . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_high / $_SESSION['cnt']) * 100) . '%)<br />' .
<i> </i> 'Percentage of rentals with features ' . $rentals_feature . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_feature / $_SESSION['cnt']) * 100) . '%)<br />';
<i> </i>} else {
?>
<!DOCTYPE html>
<html>
<head>
<title>Need some help finishing my PHP program for class</title>
</head>
<body>
<div><p>Complete this form for rates:</p>
<form action="" method="post">
<i> </i> <p>First Name: <input type="text" name="firstname" size="20" /></p>
<i> </i> <p>Last Name: <input type="text" name="lastname" size="20" /></p>
<i> </i> <p>Initial Deposit: <input type="text" name="deposit" size="20" /></p>
<i> </i> <p>Number of Days Rental: <input type="text" name="days" size="3" /></p>
<i> </i> <p>Beginning Mileage: <input type="text" name="beginningmileage" size="10" /></p>
<i> </i> <p>Ending Mileage: <input type="text" name="endmileage" size="10" /></p>
<i> </i> <p>Insurance: <select name="coverage">
<i> </i> <option value="1">Yes</option>
<i> </i> <option value="0">No</option>
<i> </i> </select></p>
<i> </i> <p>Customer Type;
<i> </i> <select name="discount">
<i> </i> <option value="0">Retail</option>
<i> </i> <option value=".1">Preferred</option>
<i> </i> <option value=".15 ">Corporate</option>
<i> </i> </select></p>
<i> </i> <p>Number of Drivers: <select name="drivers">
<i> </i> <option value="1">1</option>
<i> </i> <option value="2">2</option>
<i> </i> <option value="3">3</option>
<i> </i> <option value="4">4</option>
<i> </i> <option value="5">5</option>
<i> </i> <option value="6">6</option>
<i> </i> <option value="7">7</option>
<i> </i> <option value="8">8</option>
<i> </i> </select></p>
<i> </i> <p>Choose Model: <select name="model">
<i> </i> <option value="20">Subcompact</option>
<i> </i> <option value="25">Compact</option>
<i> </i> <option value="30">Mid-Size</option>
<i> </i> <option value="40">Luxury</option>
<i> </i> <option value="80">Minivan</option>
<i> </i> <option value="60">SUV</option>
<i> </i> </select></p>
<i> </i> <p>Under 25?: <select name="age">
<i> </i> <option value="0">0</option>
<i> </i> <option value="2.50">1</option>
<i> </i> <option value="5.00">2</option>
<i> </i> <option value="7.50">3</option>
<i> </i> </select></p>
<i> </i> <p>Gas tank: <select name="gas">
<i> </i> <option value="E">Bring it empty</option>
<i> </i> <option value="F">Bring it full</option>
<i> </i> </select></p>
<i> </i> <p>Number gallons: <input type="text" name="gallons" size="3" /></p>
<i> </i> <input type="hidden" name="first_time" value="true" />
<i> </i> <p> Extra Features;</p>
<i> </i> <input type="checkbox" name="features[]" value="5.00"/>DVD Player
<i> </i> <input type="checkbox" name="features[]" value="10.00"/>Multi-CD/MP3 Player
<i> </i> <input type="checkbox" name="features[]" value="3.00"/>Satellite Radio
<i> </i> <input type="checkbox" name="features[]" value="5.00"/>GPS
<i> </i> <input type="submit" name="submit" value="Submit Form" />
<i> </i> </form>
<i> </i> </div>
<i> </i></body>
</html>
<?php
<i> </i>}
?>
OK, might not be perfect... but it worked with the data I entered.
Your calculations look like they need a little work as well ?
[/QUOTE]
<?php
<i> </i>session_start();
<i> </i>if (!(isset($_POST['first_time']))) {
<i> </i> $_SESSION['cnt'] = 0;
<i> </i> $_SESSION['fin'] = 0;
<i> </i>}
<i> </i>if (isset($_POST['submit'])) { //TODO: Address error handling
<i> </i> // Get the values from the $_POST array:
<i> </i> $firstname = $_POST['firstname'];
<i> </i> $lastname = $_POST['lastname'];
<i> </i> $deposit = $_POST['deposit'];
<i> </i> $days = (int)$_POST['days'];
<i> </i> $beginningmileage = (int)$_POST['beginningmileage'];
<i> </i> $endmileage = (int)$_POST['endmileage'];
<i> </i> $ins = $_POST['coverage'];
<i> </i> $discount = $_POST['discount'];
<i> </i> $drivers = $_POST['drivers'];
<i> </i> $model = (int)$_POST['model'];
<i> </i> $under25 = $_POST['age'];
<i> </i> $gastank = $_POST['gas'];
<i> </i> $gallons = $_POST['gallons'];
<i> </i> $features = isset($_POST['features']) ? $_POST['features'] : array();
<i> </i> $okay = true;
<i> </i> // Validate the firstname
<i> </i> if(!$firstname) {echo '<p> Please enter your first name.</p>'; $okay = false;}
<i> </i> // Validate the lastname
<i> </i> if(!$lastname) {echo '<p> Please enter your last name.</p>'; $okay = false;}
<i> </i> //Check that days is greater then 0.
<i> </i> if (!$days) {echo '<p> You must enter days greater then 0</p>'; $okay = false;}
<i> </i> //Calculate the total:
<i> </i> $daily = $model * $days;
<i> </i> $mileage = ($endmileage - $beginningmileage - ($days * 100)) * .35;
<i> </i> if ($mileage < 0) {$mileage = 0;}
<i> </i> $drivers = ($drivers - 1) * 5 * $days;
<i> </i> $sub = $daily + $mileage + $drivers; // + $features;
<i> </i> $coverage = $sub * .1 * $ins;
<i> </i> $tax = $sub * 0.05;
<i> </i> $tot = 0;
<i> </i> foreach ($features as $charge) {
<i> </i> $tot = $tot + $charge;
<i> </i> }
<i> </i> $extra = $tot * $days;
<i> </i> $fin = $sub + $coverage + $tax + $extra - $deposit;
<i> </i> $fin = $fin - ($fin * $discount);
<i> </i> $daily = number_format($daily, 2);
<i> </i> echo "daily:$$daily<br />";
<i> </i> $mileage = number_format($mileage, 2);
<i> </i> echo 'mileage:$$mileage<br />';
<i> </i> /*print "mileage chargeprin:<br/>
<i> </i> */
<i> </i> $drivers = number_format($drivers, 2);
<i> </i> echo "drivers:$$drivers<br />";
<i> </i> $underdrivers = $under25 * $days;
<i> </i> if ($gastank == 'E') {$gascharge = $gallons * 3;} else
<i> </i> {$gascharge = $gallons * 3;}
<i> </i> $sub = number_format($sub, 2);
<i> </i> echo "extra:$$extra<br />";
<i> </i> echo "discount:$discount<br />";
<i> </i> echo "sub:$$sub<br />";
<i> </i> $coverage = number_format($coverage, 2);
<i> </i> echo "coverage:$$coverage<br />";
<i> </i> $fin = number_format($fin, 2);
<i> </i> echo "fin:$$fin<br />";
<i> </i> $_SESSION['cnt'] = $_SESSION['cnt'] + 1;
<i> </i> $_SESSION['fin'] = $_SESSION['fin'] + $fin;
<i> </i> $_SESSION['entry' . $_SESSION['cnt']] = array(
<i> </i> 'model' => $model,
<i> </i> 'features' => $features
<i> </i> );
<i> </i> echo
<i> </i> '<form method="post" action="">
<i> </i> <p><input name="rentals" value="Enter New Rental" type="submit"></p>
<i> </i> <p><input name="finish" value="Complete All Rentals" type="submit"></p>
<i> </i> <input type="hidden" name="first_time" value="true">
<i> </i> </form>';
<i> </i>} else
<i> </i>if (isset($_POST['finish'])) {
<i> </i> $rentals_high = 0;
<i> </i> $rentals_feature = 0;
<i> </i> for ($i = 1; $i <= $_SESSION['cnt']; ++$i) {$j = $_SESSION['entry' . $i];
<i> </i> //Percentage of rentals which were high end models (luxury, minivan, suv)
<i> </i> if ($j['model'] > 30) {$rentals_high++;}
<i> </i> //Percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS.
<i> </i> if (count($j['features'])) {$rentals_feature++;}
<i> </i> }
<i> </i> echo
<i> </i> 'Summary Form<br />' .
<i> </i> 'Here is the count ' . $_SESSION['cnt'] . '<br />' .
<i> </i> 'Total amount of all rentals ' . $_SESSION['fin'] . '<br />' .
<i> </i> 'Percentage of high end models ' . $rentals_high . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_high / $_SESSION['cnt']) * 100) . '%)<br />' .
<i> </i> 'Percentage of rentals with features ' . $rentals_feature . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_feature / $_SESSION['cnt']) * 100) . '%)<br />';
<i> </i>} else {
?>
<!DOCTYPE html>
<html>
<head>
<title>Need some help finishing my PHP program for class</title>
</head>
<body>
<div><p>Complete this form for rates:</p>
<form action="" method="post">
<i> </i> <p>First Name: <input type="text" name="firstname" size="20" /></p>
<i> </i> <p>Last Name: <input type="text" name="lastname" size="20" /></p>
<i> </i> <p>Initial Deposit: <input type="text" name="deposit" size="20" /></p>
<i> </i> <p>Number of Days Rental: <input type="text" name="days" size="3" /></p>
<i> </i> <p>Beginning Mileage: <input type="text" name="beginningmileage" size="10" /></p>
<i> </i> <p>Ending Mileage: <input type="text" name="endmileage" size="10" /></p>
<i> </i> <p>Insurance: <select name="coverage">
<i> </i> <option value="1">Yes</option>
<i> </i> <option value="0">No</option>
<i> </i> </select></p>
<i> </i> <p>Customer Type;
<i> </i> <select name="discount">
<i> </i> <option value="0">Retail</option>
<i> </i> <option value=".1">Preferred</option>
<i> </i> <option value=".15 ">Corporate</option>
<i> </i> </select></p>
<i> </i> <p>Number of Drivers: <select name="drivers">
<i> </i> <option value="1">1</option>
<i> </i> <option value="2">2</option>
<i> </i> <option value="3">3</option>
<i> </i> <option value="4">4</option>
<i> </i> <option value="5">5</option>
<i> </i> <option value="6">6</option>
<i> </i> <option value="7">7</option>
<i> </i> <option value="8">8</option>
<i> </i> </select></p>
<i> </i> <p>Choose Model: <select name="model">
<i> </i> <option value="20">Subcompact</option>
<i> </i> <option value="25">Compact</option>
<i> </i> <option value="30">Mid-Size</option>
<i> </i> <option value="40">Luxury</option>
<i> </i> <option value="80">Minivan</option>
<i> </i> <option value="60">SUV</option>
<i> </i> </select></p>
<i> </i> <p>Under 25?: <select name="age">
<i> </i> <option value="0">0</option>
<i> </i> <option value="2.50">1</option>
<i> </i> <option value="5.00">2</option>
<i> </i> <option value="7.50">3</option>
<i> </i> </select></p>
<i> </i> <p>Gas tank: <select name="gas">
<i> </i> <option value="E">Bring it empty</option>
<i> </i> <option value="F">Bring it full</option>
<i> </i> </select></p>
<i> </i> <p>Number gallons: <input type="text" name="gallons" size="3" /></p>
<i> </i> <input type="hidden" name="first_time" value="true" />
<i> </i> <p> Extra Features;</p>
<i> </i> <input type="checkbox" name="features[]" value="5.00"/>DVD Player
<i> </i> <input type="checkbox" name="features[]" value="10.00"/>Multi-CD/MP3 Player
<i> </i> <input type="checkbox" name="features[]" value="3.00"/>Satellite Radio
<i> </i> <input type="checkbox" name="features[]" value="5.00"/>GPS
<i> </i> <input type="submit" name="submit" value="Submit Form" />
<i> </i> </form>
<i> </i> </div>
<i> </i></body>
</html>
<?php
<i> </i>}
?>
0.1.9 — BETA 6.16