www.webdeveloper.com
Page 3 of 3 FirstFirst 123
Results 31 to 36 of 36

Thread: Need some help finishing my PHP program for class

  1. #31
    Join Date
    Dec 2013
    Posts
    21
    I did but the tags around but it got messed up again......

  2. #32
    Join Date
    Dec 2013
    Posts
    21
    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"

  3. #33
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    I see that there are still some of the previously mentioned issues outstanding in this submission. Let me look through it...

  4. #34
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by bionoid View Post
    I see that there are still some of the previously mentioned issues outstanding in this submission. Let me look through it...
    I appreciate you helping me out in tough time.

  5. #35
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    OK, might not be perfect... but it worked with the data I entered.
    Your calculations look like they need a little work as well :P

    Code:
    <?php
    
    	session_start();
    
    	if (!(isset($_POST['first_time']))) {
    		$_SESSION['cnt'] = 0;
    		$_SESSION['fin'] = 0;
    	}
    
    	if (isset($_POST['submit'])) { //TODO: Address error handling
    
    		// Get the values from the $_POST array:
    		$firstname        = $_POST['firstname'];
    		$lastname         = $_POST['lastname'];
    		$deposit          = $_POST['deposit'];
    		$days             = (int)$_POST['days'];
    		$beginningmileage = (int)$_POST['beginningmileage'];
    		$endmileage       = (int)$_POST['endmileage'];
    		$ins              = $_POST['coverage'];
    		$discount         = $_POST['discount'];
    		$drivers          = $_POST['drivers'];
    		$model            = (int)$_POST['model'];
    		$under25          = $_POST['age'];
    		$gastank          = $_POST['gas'];
    		$gallons          = $_POST['gallons'];
    		$features         = isset($_POST['features']) ? $_POST['features'] : array();
    
    		$okay = true;
    
    		// Validate the firstname
    		if(!$firstname) {echo '<p> Please enter your first name.</p>'; $okay = false;}
    
    		// Validate the lastname
    		if(!$lastname) {echo '<p> Please enter your last name.</p>'; $okay = false;}
    
    		//Check that days is greater then 0.
    		if (!$days) {echo '<p> You must enter days greater then 0</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);
    		echo "daily:$$daily<br />";
    		$mileage = number_format($mileage, 2);
    		echo 'mileage:$$mileage<br />';
    		/*print "mileage chargeprin:<br/>
    		*/
    		$drivers = number_format($drivers, 2);
    		echo "drivers:$$drivers<br />";
    		$underdrivers = $under25 * $days;
    		if ($gastank == 'E') {$gascharge = $gallons * 3;} else
    		                     {$gascharge = $gallons * 3;}
    		$sub = number_format($sub, 2);
    		echo "extra:$$extra<br />";
    		echo "discount:$discount<br />";
    		echo "sub:$$sub<br />";
    		$coverage = number_format($coverage, 2);
    		echo "coverage:$$coverage<br />";
    		$fin = number_format($fin, 2);
    		echo "fin:$$fin<br />";
    
    		$_SESSION['cnt'] = $_SESSION['cnt'] + 1;
    		$_SESSION['fin'] = $_SESSION['fin'] + $fin;
    		$_SESSION['entry' . $_SESSION['cnt']] = array(
    
    			'model'    => $model,
    			'features' => $features
    
    		);
    
    		echo
    			'<form method="post" action="">
    				<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'])) {
    
    		$rentals_high = 0;
    		$rentals_feature = 0;
    		for ($i = 1; $i <= $_SESSION['cnt']; ++$i) {$j = $_SESSION['entry' . $i];
    
    			//Percentage of rentals which were high end models (luxury, minivan, suv)
    			if ($j['model'] > 30) {$rentals_high++;}
    
    			//Percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS.
    			if (count($j['features'])) {$rentals_feature++;}
    
    		}
    
    		echo
    			'Summary Form<br />' .
    			'Here is the count ' . $_SESSION['cnt'] . '<br />' .
    			'Total amount of all rentals ' . $_SESSION['fin'] . '<br />' .
    			'Percentage of high end models ' . $rentals_high . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_high / $_SESSION['cnt']) * 100) . '%)<br />' .
    			'Percentage of rentals with features ' . $rentals_feature . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_feature / $_SESSION['cnt']) * 100) . '%)<br />';
    
    	} 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">
    
    				<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>
    				</select></p>
    
    				<p>Number gallons: <input type="text" name="gallons" size="3" /></p>
    
    				<input type="hidden" name="first_time" value="true" />
    				<p> Extra Features;</p>
    				<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
    
    	}
    
    ?>

  6. #36
    Join Date
    Dec 2013
    Posts
    21
    Quote Originally Posted by bionoid View Post
    OK, might not be perfect... but it worked with the data I entered.
    Your calculations look like they need a little work as well :P

    Code:
    <?php
    
    	session_start();
    
    	if (!(isset($_POST['first_time']))) {
    		$_SESSION['cnt'] = 0;
    		$_SESSION['fin'] = 0;
    	}
    
    	if (isset($_POST['submit'])) { //TODO: Address error handling
    
    		// Get the values from the $_POST array:
    		$firstname        = $_POST['firstname'];
    		$lastname         = $_POST['lastname'];
    		$deposit          = $_POST['deposit'];
    		$days             = (int)$_POST['days'];
    		$beginningmileage = (int)$_POST['beginningmileage'];
    		$endmileage       = (int)$_POST['endmileage'];
    		$ins              = $_POST['coverage'];
    		$discount         = $_POST['discount'];
    		$drivers          = $_POST['drivers'];
    		$model            = (int)$_POST['model'];
    		$under25          = $_POST['age'];
    		$gastank          = $_POST['gas'];
    		$gallons          = $_POST['gallons'];
    		$features         = isset($_POST['features']) ? $_POST['features'] : array();
    
    		$okay = true;
    
    		// Validate the firstname
    		if(!$firstname) {echo '<p> Please enter your first name.</p>'; $okay = false;}
    
    		// Validate the lastname
    		if(!$lastname) {echo '<p> Please enter your last name.</p>'; $okay = false;}
    
    		//Check that days is greater then 0.
    		if (!$days) {echo '<p> You must enter days greater then 0</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);
    		echo "daily:$$daily<br />";
    		$mileage = number_format($mileage, 2);
    		echo 'mileage:$$mileage<br />';
    		/*print "mileage chargeprin:<br/>
    		*/
    		$drivers = number_format($drivers, 2);
    		echo "drivers:$$drivers<br />";
    		$underdrivers = $under25 * $days;
    		if ($gastank == 'E') {$gascharge = $gallons * 3;} else
    		                     {$gascharge = $gallons * 3;}
    		$sub = number_format($sub, 2);
    		echo "extra:$$extra<br />";
    		echo "discount:$discount<br />";
    		echo "sub:$$sub<br />";
    		$coverage = number_format($coverage, 2);
    		echo "coverage:$$coverage<br />";
    		$fin = number_format($fin, 2);
    		echo "fin:$$fin<br />";
    
    		$_SESSION['cnt'] = $_SESSION['cnt'] + 1;
    		$_SESSION['fin'] = $_SESSION['fin'] + $fin;
    		$_SESSION['entry' . $_SESSION['cnt']] = array(
    
    			'model'    => $model,
    			'features' => $features
    
    		);
    
    		echo
    			'<form method="post" action="">
    				<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'])) {
    
    		$rentals_high = 0;
    		$rentals_feature = 0;
    		for ($i = 1; $i <= $_SESSION['cnt']; ++$i) {$j = $_SESSION['entry' . $i];
    
    			//Percentage of rentals which were high end models (luxury, minivan, suv)
    			if ($j['model'] > 30) {$rentals_high++;}
    
    			//Percentage of rentals selected as least one "extra - dvd ,cd, satellite ,GPS.
    			if (count($j['features'])) {$rentals_feature++;}
    
    		}
    
    		echo
    			'Summary Form<br />' .
    			'Here is the count ' . $_SESSION['cnt'] . '<br />' .
    			'Total amount of all rentals ' . $_SESSION['fin'] . '<br />' .
    			'Percentage of high end models ' . $rentals_high . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_high / $_SESSION['cnt']) * 100) . '%)<br />' .
    			'Percentage of rentals with features ' . $rentals_feature . '/' . $_SESSION['cnt'] . ' (' . round(($rentals_feature / $_SESSION['cnt']) * 100) . '%)<br />';
    
    	} 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">
    
    				<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>
    				</select></p>
    
    				<p>Number gallons: <input type="text" name="gallons" size="3" /></p>
    
    				<input type="hidden" name="first_time" value="true" />
    				<p> Extra Features;</p>
    				<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
    
    	}
    
    ?>
    You are the best!!!! I tried running this code it's working awesome. Thanks so much. I really appreciate you helping.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles