/    Sign up×
Community /Pin to ProfileBookmark

Need some help finishing my PHP program for class

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[‘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 {

?>
<!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.

to post a comment
PHP

35 Comments(s)

Copy linkTweet thisAlerts:
@unasAquilaDec 21.2013 — 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.
Copy linkTweet thisAlerts:
@LaddiauthorDec 21.2013 — Hello sorry I didn't know that and thanks for fixing it for me. I think I got A and B I need help putting a break into them. A and B are currently showing results on the same line. Lastly I need help with putting C and D which are % to the summary page.


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]
Copy linkTweet thisAlerts:
@ginerjmDec 21.2013 — Yes - with ALL this code it would be nice if you told us what you were looking for....
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — Yes - with ALL this code it would be nice if you told us what you were looking for....[/QUOTE]

In my post there are 4 things A through D I listed under professors instructions that's what I need help on. How to add % to my summary page.
Copy linkTweet thisAlerts:
@ginerjmDec 22.2013 — 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"?
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — 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]

The problem is I don't know how to add it. I'm sorry but I am completely lost here.
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — Thanks for making my post better for viewing. I am new here I didn't know how to do it my self.
Copy linkTweet thisAlerts:
@ginerjmDec 22.2013 — 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?
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — 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]

Well yes I did write the code using my book as reference. I had to return my book back since it was rented. I am beginner of PHP don't know much about it.
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — Could someone please help me out.
Copy linkTweet thisAlerts:
@ginerjmDec 22.2013 — 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?
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — 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]

My major is psychology not web development. I took this PHP class as a free elective to give it a shot for fun. It was very hard for me since computers is not my major. I did run the code it's running perfect. I just need final touch to it. I need to display percentage on the summary page. What percentage of rentals which were high end models (luxury, minivan, suv) and lastly percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS.. I could help that would be appreciated.
Copy linkTweet thisAlerts:
@unasAquilaDec 22.2013 — 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.
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — 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]


Thanks for making these changes. I need to add two things on the summary page. I need to display percentage on the summary page. What percentage of rentals which were high end models (luxury, minivan, suv) and lastly percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS. The problem I am having is how to add percentage on the summary page.
Copy linkTweet thisAlerts:
@bionoidDec 22.2013 — Additional corrections to be mentioned:

[B]Line 116:[/B] (missing bracket)
&lt;!DOCTYPE html[COLOR="#FF0000"]&gt;[/COLOR]

[B]Line 143+[/B] (unquoted attributes)
&lt;option value=[COLOR="#FF0000"]"[/COLOR]1[COLOR="#FF0000"]"[/COLOR]&gt;1&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]2[COLOR="#FF0000"]"[/COLOR]&gt;2&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]3[COLOR="#FF0000"]"[/COLOR]&gt;3&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]4[COLOR="#FF0000"]"[/COLOR]&gt;4&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]5[COLOR="#FF0000"]"[/COLOR]&gt;5&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]6[COLOR="#FF0000"]"[/COLOR]&gt;6&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]7[COLOR="#FF0000"]"[/COLOR]&gt;7&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]8[COLOR="#FF0000"]"[/COLOR]&gt;8&lt;/option&gt;


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' =&gt; $model,
<i> </i>'features' =&gt; $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] =&gt; 3
[fin] =&gt; 2986.95
[entry1] =&gt; Array
(
[model] =&gt; 30
[features] =&gt; Array
(
[0] =&gt; 10.00
[1] =&gt; 3.00
)

<i> </i> )

<i> </i>[entry2] =&gt; Array
<i> </i> (
<i> </i> [model] =&gt; 30
<i> </i> [features] =&gt; Array
<i> </i> (
<i> </i> [0] =&gt; 10.00
<i> </i> [1] =&gt; 3.00
<i> </i> )

<i> </i> )

<i> </i>[entry3] =&gt; Array
<i> </i> (
<i> </i> [model] =&gt; 30
<i> </i> [features] =&gt; Array
<i> </i> (
<i> </i> [0] =&gt; 10.00
<i> </i> [1] =&gt; 3.00
<i> </i> )

<i> </i> )

)


You could then loop through the data at a later stage and sum it up.
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — Additional corrections to be mentioned:

[B]Line 116:[/B] (missing bracket)
&lt;!DOCTYPE html[COLOR="#FF0000"]&gt;[/COLOR]

[B]Line 143+[/B] (unquoted attributes)
&lt;option value=[COLOR="#FF0000"]"[/COLOR]1[COLOR="#FF0000"]"[/COLOR]&gt;1&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]2[COLOR="#FF0000"]"[/COLOR]&gt;2&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]3[COLOR="#FF0000"]"[/COLOR]&gt;3&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]4[COLOR="#FF0000"]"[/COLOR]&gt;4&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]5[COLOR="#FF0000"]"[/COLOR]&gt;5&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]6[COLOR="#FF0000"]"[/COLOR]&gt;6&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]7[COLOR="#FF0000"]"[/COLOR]&gt;7&lt;/option&gt;
&lt;option value=[COLOR="#FF0000"]"[/COLOR]8[COLOR="#FF0000"]"[/COLOR]&gt;8&lt;/option&gt;


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' =&gt; $model,
<i> </i>'features' =&gt; $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] =&gt; 3
[fin] =&gt; 2986.95
[entry1] =&gt; Array
(
[model] =&gt; 30
[features] =&gt; Array
(
[0] =&gt; 10.00
[1] =&gt; 3.00
)

<i> </i> )

<i> </i>[entry2] =&gt; Array
<i> </i> (
<i> </i> [model] =&gt; 30
<i> </i> [features] =&gt; Array
<i> </i> (
<i> </i> [0] =&gt; 10.00
<i> </i> [1] =&gt; 3.00
<i> </i> )

<i> </i> )

<i> </i>[entry3] =&gt; Array
<i> </i> (
<i> </i> [model] =&gt; 30
<i> </i> [features] =&gt; Array
<i> </i> (
<i> </i> [0] =&gt; 10.00
<i> </i> [1] =&gt; 3.00
<i> </i> )

<i> </i> )

)


You could then loop through the data at a later stage and sum it up.[/QUOTE]



Thanks for taking your valuable time out and helping me. I am new in PHP. You said "After a few submission your session data would end up like this (using print_r($_SESSION)?:" so all the have to go in the print statement?
Copy linkTweet thisAlerts:
@bionoidDec 22.2013 — [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 &lt;= $_SESSION['cnt']; ++$i) {

<i> </i>echo 'Entry ' . $i . ' = ' . $_SESSION['entry' . $i]['model'] . ' / ' . count($_SESSION['entry' . $i]['features']) . '&lt;br /&gt;';

}


Output Example (data dependant):
Entry 1 = 30 / 2

Entry 2 = 30 / 2

Entry 3 = 30 / 2[/QUOTE]
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — [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 &lt;= $_SESSION['cnt']; ++$i) {

<i> </i>echo 'Entry ' . $i . ' = ' . $_SESSION['entry' . $i]['model'] . ' / ' . count($_SESSION['entry' . $i]['features']) . '&lt;br /&gt;';

}


Output Example (data dependant):[/QUOTE]


You been a great help! Thanks a lot.
Copy linkTweet thisAlerts:
@ginerjmDec 22.2013 — 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.
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — 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]


If you don't trust me you can try to upload my script on the server and give it a shot. There is no reason for me to lie. Anyways thanks for your recommendation sir!
Copy linkTweet thisAlerts:
@unasAquilaDec 22.2013 — 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.
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — 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 do understand what you mean. The problem is if I knew how to do it, I wont be asking help. I know it's not much left probably few more lines. It's my mistake I took PHP class as a free elective. Earlier I was accused of lying without the person running my script. I am not here to argue with other users but others should check before they accuse someone. Anyhow I appreciate you helping me out.
Copy linkTweet thisAlerts:
@bionoidDec 22.2013 — I'm curious to know when this is due, I thought most places had already closed for the holidays?
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — I'm curious to know when this is due, I thought most places had already closed for the holidays?[/QUOTE]

This is due tomorrow before midnight.
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — I'm curious to know when this is due, I thought most places had already closed for the holidays?[/QUOTE]

It's a online class, I requested my instructor for late assignment submission.
Copy linkTweet thisAlerts:
@bionoidDec 22.2013 — OK, then how are you coming along? Do you have what you need to complete it now?
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — OK, then how are you coming along? Do you have what you need to complete it now?[/QUOTE]

I don't understand how to put the code in for summary percentage. To be honest I'm still completely lost. When I make changes the page turns blank (white)
Copy linkTweet thisAlerts:
@bionoidDec 22.2013 — ok, whatever you've done... post it here again. remember to place [ code ][ /code ] tags without the spaces around it. Then we can sort this out.

I don't think you included the final page code here before anyway, would be nice to see.
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — <?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['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($_
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/>";

print $_SESSION['cnt'] = $_SESSION['cnt'] + 1;

print $_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"

print "Here is the count " . $_
SESSION['cnt']<br/>;

print "Total amount of all rentals" . $_SESSION['fin'];<br/>




}

else {


?>
Copy linkTweet thisAlerts:
@LaddiauthorDec 22.2013 — I did but the tags around but it got messed up again......
Copy linkTweet thisAlerts:
@LaddiauthorDec 23.2013 — So far what I tried to do it put a break in where it says print summary page, print " Here is the count" and print " Total amount of all rentals"
Copy linkTweet thisAlerts:
@bionoidDec 23.2013 — I see that ? there are still some of the previously mentioned issues outstanding in this submission. Let me look through it...
Copy linkTweet thisAlerts:
@LaddiauthorDec 23.2013 — I see that ? there are still some of the previously mentioned issues outstanding in this submission. Let me look through it...[/QUOTE]

I appreciate you helping me out in tough time.
Copy linkTweet thisAlerts:
@bionoidDec 23.2013 — OK, might not be perfect... but it worked with the data I entered.

Your calculations look like they need a little work as well ?

&lt;?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 '&lt;p&gt; Please enter your first name.&lt;/p&gt;'; $okay = false;}

<i> </i> // Validate the lastname
<i> </i> if(!$lastname) {echo '&lt;p&gt; Please enter your last name.&lt;/p&gt;'; $okay = false;}

<i> </i> //Check that days is greater then 0.
<i> </i> if (!$days) {echo '&lt;p&gt; You must enter days greater then 0&lt;/p&gt;'; $okay = false;}

<i> </i> //Calculate the total:
<i> </i> $daily = $model * $days;
<i> </i> $mileage = ($endmileage - $beginningmileage - ($days * 100)) * .35;
<i> </i> if ($mileage &lt; 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&lt;br /&gt;";
<i> </i> $mileage = number_format($mileage, 2);
<i> </i> echo 'mileage:$$mileage&lt;br /&gt;';
<i> </i> /*print "mileage chargeprin:&lt;br/&gt;
<i> </i> */
<i> </i> $drivers = number_format($drivers, 2);
<i> </i> echo "drivers:$$drivers&lt;br /&gt;";
<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&lt;br /&gt;";
<i> </i> echo "discount:$discount&lt;br /&gt;";
<i> </i> echo "sub:$$sub&lt;br /&gt;";
<i> </i> $coverage = number_format($coverage, 2);
<i> </i> echo "coverage:$$coverage&lt;br /&gt;";
<i> </i> $fin = number_format($fin, 2);
<i> </i> echo "fin:$$fin&lt;br /&gt;";

<i> </i> $_SESSION['cnt'] = $_SESSION['cnt'] + 1;
<i> </i> $_SESSION['fin'] = $_SESSION['fin'] + $fin;
<i> </i> $_SESSION['entry' . $_SESSION['cnt']] = array(

<i> </i> 'model' =&gt; $model,
<i> </i> 'features' =&gt; $features

<i> </i> );

<i> </i> echo
<i> </i> '&lt;form method="post" action=""&gt;
<i> </i> &lt;p&gt;&lt;input name="rentals" value="Enter New Rental" type="submit"&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;&lt;input name="finish" value="Complete All Rentals" type="submit"&gt;&lt;/p&gt;
<i> </i> &lt;input type="hidden" name="first_time" value="true"&gt;
<i> </i> &lt;/form&gt;';

<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 &lt;= $_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'] &gt; 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&lt;br /&gt;' .
<i> </i> 'Here is the count ' . $_SESSION['cnt'] . '&lt;br /&gt;' .
<i> </i> 'Total amount of all rentals ' . $_SESSION['fin'] . '&lt;br /&gt;' .
<i> </i> 'Percentage of high end models ' . $rentals_high . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_high / $_SESSION['cnt']) * 100) . '%)&lt;br /&gt;' .
<i> </i> 'Percentage of rentals with features ' . $rentals_feature . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_feature / $_SESSION['cnt']) * 100) . '%)&lt;br /&gt;';

<i> </i>} else {

?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Need some help finishing my PHP program for class&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div&gt;&lt;p&gt;Complete this form for rates:&lt;/p&gt;
&lt;form action="" method="post"&gt;

<i> </i> &lt;p&gt;First Name: &lt;input type="text" name="firstname" size="20" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Last Name: &lt;input type="text" name="lastname" size="20" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Initial Deposit: &lt;input type="text" name="deposit" size="20" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Number of Days Rental: &lt;input type="text" name="days" size="3" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Beginning Mileage: &lt;input type="text" name="beginningmileage" size="10" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Ending Mileage: &lt;input type="text" name="endmileage" size="10" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Insurance: &lt;select name="coverage"&gt;
<i> </i> &lt;option value="1"&gt;Yes&lt;/option&gt;
<i> </i> &lt;option value="0"&gt;No&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Customer Type;
<i> </i> &lt;select name="discount"&gt;
<i> </i> &lt;option value="0"&gt;Retail&lt;/option&gt;
<i> </i> &lt;option value=".1"&gt;Preferred&lt;/option&gt;
<i> </i> &lt;option value=".15 "&gt;Corporate&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;


<i> </i> &lt;p&gt;Number of Drivers: &lt;select name="drivers"&gt;
<i> </i> &lt;option value="1"&gt;1&lt;/option&gt;
<i> </i> &lt;option value="2"&gt;2&lt;/option&gt;
<i> </i> &lt;option value="3"&gt;3&lt;/option&gt;
<i> </i> &lt;option value="4"&gt;4&lt;/option&gt;
<i> </i> &lt;option value="5"&gt;5&lt;/option&gt;
<i> </i> &lt;option value="6"&gt;6&lt;/option&gt;
<i> </i> &lt;option value="7"&gt;7&lt;/option&gt;
<i> </i> &lt;option value="8"&gt;8&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Choose Model: &lt;select name="model"&gt;
<i> </i> &lt;option value="20"&gt;Subcompact&lt;/option&gt;
<i> </i> &lt;option value="25"&gt;Compact&lt;/option&gt;
<i> </i> &lt;option value="30"&gt;Mid-Size&lt;/option&gt;
<i> </i> &lt;option value="40"&gt;Luxury&lt;/option&gt;
<i> </i> &lt;option value="80"&gt;Minivan&lt;/option&gt;
<i> </i> &lt;option value="60"&gt;SUV&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Under 25?: &lt;select name="age"&gt;
<i> </i> &lt;option value="0"&gt;0&lt;/option&gt;
<i> </i> &lt;option value="2.50"&gt;1&lt;/option&gt;
<i> </i> &lt;option value="5.00"&gt;2&lt;/option&gt;
<i> </i> &lt;option value="7.50"&gt;3&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Gas tank: &lt;select name="gas"&gt;
<i> </i> &lt;option value="E"&gt;Bring it empty&lt;/option&gt;
<i> </i> &lt;option value="F"&gt;Bring it full&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Number gallons: &lt;input type="text" name="gallons" size="3" /&gt;&lt;/p&gt;

<i> </i> &lt;input type="hidden" name="first_time" value="true" /&gt;
<i> </i> &lt;p&gt; Extra Features;&lt;/p&gt;
<i> </i> &lt;input type="checkbox" name="features[]" value="5.00"/&gt;DVD Player
<i> </i> &lt;input type="checkbox" name="features[]" value="10.00"/&gt;Multi-CD/MP3 Player
<i> </i> &lt;input type="checkbox" name="features[]" value="3.00"/&gt;Satellite Radio
<i> </i> &lt;input type="checkbox" name="features[]" value="5.00"/&gt;GPS
<i> </i> &lt;input type="submit" name="submit" value="Submit Form" /&gt;

<i> </i> &lt;/form&gt;
<i> </i> &lt;/div&gt;
<i> </i>&lt;/body&gt;
&lt;/html&gt;
&lt;?php

<i> </i>}

?&gt;
Copy linkTweet thisAlerts:
@LaddiauthorDec 23.2013 — OK, might not be perfect... but it worked with the data I entered.

Your calculations look like they need a little work as well ?

&lt;?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 '&lt;p&gt; Please enter your first name.&lt;/p&gt;'; $okay = false;}

<i> </i> // Validate the lastname
<i> </i> if(!$lastname) {echo '&lt;p&gt; Please enter your last name.&lt;/p&gt;'; $okay = false;}

<i> </i> //Check that days is greater then 0.
<i> </i> if (!$days) {echo '&lt;p&gt; You must enter days greater then 0&lt;/p&gt;'; $okay = false;}

<i> </i> //Calculate the total:
<i> </i> $daily = $model * $days;
<i> </i> $mileage = ($endmileage - $beginningmileage - ($days * 100)) * .35;
<i> </i> if ($mileage &lt; 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&lt;br /&gt;";
<i> </i> $mileage = number_format($mileage, 2);
<i> </i> echo 'mileage:$$mileage&lt;br /&gt;';
<i> </i> /*print "mileage chargeprin:&lt;br/&gt;
<i> </i> */
<i> </i> $drivers = number_format($drivers, 2);
<i> </i> echo "drivers:$$drivers&lt;br /&gt;";
<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&lt;br /&gt;";
<i> </i> echo "discount:$discount&lt;br /&gt;";
<i> </i> echo "sub:$$sub&lt;br /&gt;";
<i> </i> $coverage = number_format($coverage, 2);
<i> </i> echo "coverage:$$coverage&lt;br /&gt;";
<i> </i> $fin = number_format($fin, 2);
<i> </i> echo "fin:$$fin&lt;br /&gt;";

<i> </i> $_SESSION['cnt'] = $_SESSION['cnt'] + 1;
<i> </i> $_SESSION['fin'] = $_SESSION['fin'] + $fin;
<i> </i> $_SESSION['entry' . $_SESSION['cnt']] = array(

<i> </i> 'model' =&gt; $model,
<i> </i> 'features' =&gt; $features

<i> </i> );

<i> </i> echo
<i> </i> '&lt;form method="post" action=""&gt;
<i> </i> &lt;p&gt;&lt;input name="rentals" value="Enter New Rental" type="submit"&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;&lt;input name="finish" value="Complete All Rentals" type="submit"&gt;&lt;/p&gt;
<i> </i> &lt;input type="hidden" name="first_time" value="true"&gt;
<i> </i> &lt;/form&gt;';

<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 &lt;= $_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'] &gt; 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&lt;br /&gt;' .
<i> </i> 'Here is the count ' . $_SESSION['cnt'] . '&lt;br /&gt;' .
<i> </i> 'Total amount of all rentals ' . $_SESSION['fin'] . '&lt;br /&gt;' .
<i> </i> 'Percentage of high end models ' . $rentals_high . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_high / $_SESSION['cnt']) * 100) . '%)&lt;br /&gt;' .
<i> </i> 'Percentage of rentals with features ' . $rentals_feature . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_feature / $_SESSION['cnt']) * 100) . '%)&lt;br /&gt;';

<i> </i>} else {

?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Need some help finishing my PHP program for class&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div&gt;&lt;p&gt;Complete this form for rates:&lt;/p&gt;
&lt;form action="" method="post"&gt;

<i> </i> &lt;p&gt;First Name: &lt;input type="text" name="firstname" size="20" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Last Name: &lt;input type="text" name="lastname" size="20" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Initial Deposit: &lt;input type="text" name="deposit" size="20" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Number of Days Rental: &lt;input type="text" name="days" size="3" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Beginning Mileage: &lt;input type="text" name="beginningmileage" size="10" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Ending Mileage: &lt;input type="text" name="endmileage" size="10" /&gt;&lt;/p&gt;
<i> </i> &lt;p&gt;Insurance: &lt;select name="coverage"&gt;
<i> </i> &lt;option value="1"&gt;Yes&lt;/option&gt;
<i> </i> &lt;option value="0"&gt;No&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Customer Type;
<i> </i> &lt;select name="discount"&gt;
<i> </i> &lt;option value="0"&gt;Retail&lt;/option&gt;
<i> </i> &lt;option value=".1"&gt;Preferred&lt;/option&gt;
<i> </i> &lt;option value=".15 "&gt;Corporate&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;


<i> </i> &lt;p&gt;Number of Drivers: &lt;select name="drivers"&gt;
<i> </i> &lt;option value="1"&gt;1&lt;/option&gt;
<i> </i> &lt;option value="2"&gt;2&lt;/option&gt;
<i> </i> &lt;option value="3"&gt;3&lt;/option&gt;
<i> </i> &lt;option value="4"&gt;4&lt;/option&gt;
<i> </i> &lt;option value="5"&gt;5&lt;/option&gt;
<i> </i> &lt;option value="6"&gt;6&lt;/option&gt;
<i> </i> &lt;option value="7"&gt;7&lt;/option&gt;
<i> </i> &lt;option value="8"&gt;8&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Choose Model: &lt;select name="model"&gt;
<i> </i> &lt;option value="20"&gt;Subcompact&lt;/option&gt;
<i> </i> &lt;option value="25"&gt;Compact&lt;/option&gt;
<i> </i> &lt;option value="30"&gt;Mid-Size&lt;/option&gt;
<i> </i> &lt;option value="40"&gt;Luxury&lt;/option&gt;
<i> </i> &lt;option value="80"&gt;Minivan&lt;/option&gt;
<i> </i> &lt;option value="60"&gt;SUV&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Under 25?: &lt;select name="age"&gt;
<i> </i> &lt;option value="0"&gt;0&lt;/option&gt;
<i> </i> &lt;option value="2.50"&gt;1&lt;/option&gt;
<i> </i> &lt;option value="5.00"&gt;2&lt;/option&gt;
<i> </i> &lt;option value="7.50"&gt;3&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Gas tank: &lt;select name="gas"&gt;
<i> </i> &lt;option value="E"&gt;Bring it empty&lt;/option&gt;
<i> </i> &lt;option value="F"&gt;Bring it full&lt;/option&gt;
<i> </i> &lt;/select&gt;&lt;/p&gt;

<i> </i> &lt;p&gt;Number gallons: &lt;input type="text" name="gallons" size="3" /&gt;&lt;/p&gt;

<i> </i> &lt;input type="hidden" name="first_time" value="true" /&gt;
<i> </i> &lt;p&gt; Extra Features;&lt;/p&gt;
<i> </i> &lt;input type="checkbox" name="features[]" value="5.00"/&gt;DVD Player
<i> </i> &lt;input type="checkbox" name="features[]" value="10.00"/&gt;Multi-CD/MP3 Player
<i> </i> &lt;input type="checkbox" name="features[]" value="3.00"/&gt;Satellite Radio
<i> </i> &lt;input type="checkbox" name="features[]" value="5.00"/&gt;GPS
<i> </i> &lt;input type="submit" name="submit" value="Submit Form" /&gt;

<i> </i> &lt;/form&gt;
<i> </i> &lt;/div&gt;
<i> </i>&lt;/body&gt;
&lt;/html&gt;
&lt;?php

<i> </i>}

?&gt;
[/QUOTE]


You are the best!!!! I tried running this code it's working awesome. Thanks so much. I really appreciate you helping.
×

Success!

Help @Laddi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...