srule_
07-28-2007, 04:22 PM
Hey, i Just made my first script ever! (YA!!!)
It is a very basic script that will give people a quote depending on what options they select from a form.
Anyway,It works fine but i would just like someone to look over it and tell me if there is a way i can write cleaner, point out any mistakes i make, and any improvements i should consider applying to my future scripts. THANKS!
<?php
//Only process if Send button was pressed
if (array_key_exists('send', $_POST)) {
//Assign Value according to numer of pages requires
if ($_POST['pages'] == 'five') {
$multi_pages ='10.00';
}
elseif ($_POST['pages'] == 'ten'){
$multi_pages = '20.00';
}
elseif ($_POST['pages'] == 'fifteen'){
$multi_pages = '30.00';
}
elseif ($_POST['pages'] == 'over_fifteen'){
$multi_pages = '40.00';
}
else {
$multi_pages = '0';
}
//Assign Value according to numer of images to be supplied
if ($_POST['images'] == 'no') {
$multi_images = '10.00';
}
elseif ($_POST['images'] == 'few'){
$multi_images = '$20.00';
}
elseif ($_POST['images'] == 'moderate'){
$multi_images = '30.00';
}
elseif ($_POST['images'] == 'lots'){
$multi_images = '40.00';
}
elseif ($_POST['images'] == 'all'){
$multi_images = '50.00';
}
else {
$multi_images = '0';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Quotes</title>
</head>
<body>
<form id="quotes" method="post" action="">
<p>How many pages will your site require?</p>
<input type="radio" name="pages" id="pages-five" value="five"> 5
<input type="radio" name="pages" id="pages-ten" value="ten"> 6-10
<input type="radio" name="pages" id="pages-fifteen" value="fifteen"> 11-15
<input type="radio" name="pages" id="pages-over16" value="over_fifteen"> 16+
<p>
<p>Will you provide us with any images to be used in this project?</p>
<input type="radio" name="images" id="images-no" value="no"> No
<input type="radio" name="images" id="images-few" value="few"> A Few
<input type="radio" name="images" id="images-moderate" value="moderate"> Moderate
<input type="radio" name="images" id="images-lots" value="lots"> Lots
<input type="radio" name="images" id="images-all" value="all"> All
<p>
<input name="send" id="send" type="submit" value="Get Quote" />
</p>
</form>
<p> Your Quote:
<?php
if (isset($_POST['pages']) && isset($_POST['images'])) {
echo '$';
echo $multi_pages + $multi_images;
}
else {
echo 'Please fill in all fields';
}
?></p>
It is a very basic script that will give people a quote depending on what options they select from a form.
Anyway,It works fine but i would just like someone to look over it and tell me if there is a way i can write cleaner, point out any mistakes i make, and any improvements i should consider applying to my future scripts. THANKS!
<?php
//Only process if Send button was pressed
if (array_key_exists('send', $_POST)) {
//Assign Value according to numer of pages requires
if ($_POST['pages'] == 'five') {
$multi_pages ='10.00';
}
elseif ($_POST['pages'] == 'ten'){
$multi_pages = '20.00';
}
elseif ($_POST['pages'] == 'fifteen'){
$multi_pages = '30.00';
}
elseif ($_POST['pages'] == 'over_fifteen'){
$multi_pages = '40.00';
}
else {
$multi_pages = '0';
}
//Assign Value according to numer of images to be supplied
if ($_POST['images'] == 'no') {
$multi_images = '10.00';
}
elseif ($_POST['images'] == 'few'){
$multi_images = '$20.00';
}
elseif ($_POST['images'] == 'moderate'){
$multi_images = '30.00';
}
elseif ($_POST['images'] == 'lots'){
$multi_images = '40.00';
}
elseif ($_POST['images'] == 'all'){
$multi_images = '50.00';
}
else {
$multi_images = '0';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Quotes</title>
</head>
<body>
<form id="quotes" method="post" action="">
<p>How many pages will your site require?</p>
<input type="radio" name="pages" id="pages-five" value="five"> 5
<input type="radio" name="pages" id="pages-ten" value="ten"> 6-10
<input type="radio" name="pages" id="pages-fifteen" value="fifteen"> 11-15
<input type="radio" name="pages" id="pages-over16" value="over_fifteen"> 16+
<p>
<p>Will you provide us with any images to be used in this project?</p>
<input type="radio" name="images" id="images-no" value="no"> No
<input type="radio" name="images" id="images-few" value="few"> A Few
<input type="radio" name="images" id="images-moderate" value="moderate"> Moderate
<input type="radio" name="images" id="images-lots" value="lots"> Lots
<input type="radio" name="images" id="images-all" value="all"> All
<p>
<input name="send" id="send" type="submit" value="Get Quote" />
</p>
</form>
<p> Your Quote:
<?php
if (isset($_POST['pages']) && isset($_POST['images'])) {
echo '$';
echo $multi_pages + $multi_images;
}
else {
echo 'Please fill in all fields';
}
?></p>