/    Sign up×
Community /Pin to ProfileBookmark

Problem with code

I am twistin’ my brain tryin’ to figure out what I’m doing wrong… I know I am probably over looking something. If anyone can give me a second look and see if you see something I don’t see:

<HTML>
<head>
<title>Zellers Carpeting Cost Estimate</title>
</head>
<?php

$bValid = true;
$strMessage = “There is a problem with the following items: “;

//set vars if there is anything in the query string

if ((count($_GET) >0)) {
$width = $_GET[‘width’];
$length = $_GET[‘length’];
$carpet = $_GET[‘carpet’];
$padding = $_GET[‘padding’];

}

if ((!is_numeric($width)) || (!is_numeric($length))) {
$bValid = false;
$strMessage = “$strMessage Width and length must be a valid numbers…”;
}
if ($carpet == “”) {
$bValid = false;
$strMessage = “$strMessage Carpet must be selected…”;
}
if ($padding == “”) {
$bValid = false;
$strMessage = “$strMessage Padding must be selected…”;
}
if (isset($_GET[‘install’]) == false) {
$bValid = false;
$strMessage = “$strMessage You must choose Installation or not”;
$install = “”;
}
else {
$install = $_GET[‘install’];
}

}
// if validation fails, set the vars to empty strings, display error message(s)

else {
$width = “”;
$length = “”;
$carpet = “”;
$padding = “”;
$install = “”;

}
if ((count($_GET)==0)||($bValid ==false)){

if ($bValid==false){
print (“<div class=’errorMsg’>$strMessage</div>”);
}

}
?>
<body>
<div id=”banner”>
<h1>Zellers Carpeting</h1>
<h2>Cost Estimate</h2>
</div>
<div class=”instructions”>Enter all the relevant parameters and click submit for an estimate
of the cost of carpeting your room</div>

<img src = <?php // select image source, depending on the carpet selection
switch ($carpet) {
case “B”:
print ‘budget.jpg’;
break;
case “S”:
print ‘standard.jpg’;
break;
case “P”:
print ‘premium.jpg’;
break;
case “”:
print ‘logo.jpg’;
}

?> />

<div id=”userinput”>
<form method=”get” name=”frmInput” action=”CarpetForm.php”>
<table>
<tr>
<td><strong>Room Dimensions (in ft):</strong></td>
<td><input type=text name=width value=”<?php print (“$width”) ?>”> x <input type=text name=length value=”<?php print(“$length”) ?>”></td>
</tr>
<tr>
<td ><strong>Type of Carpet:</strong></td>
<td>
<select name=carpet value = “<?php print (“$carpet”) ?>”>
<option value=””>Choose Carpet Type</option>
<option value=”B”>Budget</option>
<option value=”S”>Standard</option>
<option value=”P”>Premium</option>
</select>
</td>
</tr>
<tr>
<td ><strong>Type of Padding:</strong></td>
<td>
<select name=padding value=”<?php print (“$padding”) ?>”>
<option value=””>Choose Padding</option>
<option value=”S”>Standard</option>
<option value=”P”>Premium</option>
</select>
</td>
</tr>
<tr>
<td><strong>Installation Required:</strong></td>
<td>Yes<input type=radio name=install value=y>&nbsp;&nbsp;&nbsp;No<input type=radio name=install value=n></td>
</tr>
<tr>
<td align=center colspan=2><input type=”button” value=”Submit”></td>
</tr>
</table>
</form>
</div>

</body></HTML>

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@acetoneMay 06.2006 — What errors are you getting or what is the script not doing that i should be doing?
Copy linkTweet thisAlerts:
@acetoneMay 06.2006 — Try this...


<HTML>

<head>

<title>Zellers Carpeting Cost Estimate</title>

</head>

<?php


$bValid = true;

$strMessage = "There is a problem with the following items: ";

//set vars if there is anything in the query string

if ((count($_GET) >0)) {

$width = $_
GET['width'];

$length = $_GET['length'];

$carpet = $_
GET['carpet'];

$padding = $_GET['padding'];



if ((!is_numeric($width)) || (!is_numeric($length))) {

$bValid = false;

$strMessage = "$strMessage Width and length must be a valid numbers...";

}

if ($carpet == "") {

$bValid = false;

$strMessage = "$strMessage Carpet must be selected...";

}

if ($padding == "") {

$bValid = false;

$strMessage = "$strMessage Padding must be selected...";

}

if (isset($_GET['install']) == false) {

$bValid = false;

$strMessage = "$strMessage You must choose Installation or not";

$install = "";

}

else {

$install = $_
GET['install'];

}

}

// if validation fails, set the vars to empty strings, display error message(s)

else {

$width = "";

$length = "";

$carpet = "";

$padding = "";

$install = "";

}

if ((count($_GET)==0)||($bValid ==false)){

if ($bValid==false){

print ("<div class='errorMsg'>$strMessage</div>");

}

}

?>

<body>

<div id="banner">

<h1>Zellers Carpeting</h1>

<h2>Cost Estimate</h2>

</div>

<div class="instructions">Enter all the relevant parameters and click submit for an estimate

of the cost of carpeting your room</div>

<img src = <?php // select image source, depending on the carpet selection

switch ($carpet) {

case "B":

print 'budget.jpg';

break;

case "S":

print 'standard.jpg';

break;

case "P":

print 'premium.jpg';

break;

case "":

print 'logo.jpg';

}

?> />

<div id="userinput">

<form method="get" name="frmInput" action="CarpetForm.php">

<table>

<tr>

<td><strong>Room Dimensions (in ft):</strong></td>

<td><input type=text name=width value="<?php print ("$width") ?>"> x <input type=text name=length value="<?php print("$length") ?>"></td>

</tr>

<tr>

<td ><strong>Type of Carpet:</strong></td>

<td>

<select name=carpet value = "<?php print ("$carpet") ?>">

<option value="">Choose Carpet Type</option>

<option value="B">Budget</option>

<option value="S">Standard</option>

<option value="P">Premium</option>

</select>

</td>

</tr>

<tr>

<td ><strong>Type of Padding:</strong></td>

<td>

<select name=padding value="<?php print ("$padding") ?>">

<option value="">Choose Padding</option>

<option value="S">Standard</option>

<option value="P">Premium</option>

</select>

</td>

</tr>

<tr>

<td><strong>Installation Required:</strong></td>

<td>Yes<input type=radio name=install value=y>&nbsp;&nbsp;&nbsp;No<input type=radio name=install value=n></td>

</tr>

<tr>

<td align=center colspan=2><input type="button" value="Submit"></td>

</tr>

</table>

</form>

</div>

</body></HTML>
Copy linkTweet thisAlerts:
@disturbedspikeauthorMay 07.2006 — I have made more changes to my code and am still having difficulties. When I pull it up from localhost in IE I get php code on the top of the page and php code within the text boxes of the width and length boxes..here is an update of the code (with what I have added and changed):

[code=php]
<HTML>
<head>
<title>Zellers Carpeting Cost Estimate</title>
</head>
<?php


$bValid = true;
$strMessage = "There is a problem with the following items: ";
//set vars if there is anything in the query string

if ((count($_GET) >0)) {
$width = $_GET['width'];
$length = $_GET['length'];
$carpet = $_GET['carpet'];
$padding = $_GET['padding'];



if ((!is_numeric($width)) || (!is_numeric($length))) {
$bValid = false;
$strMessage = "$strMessage Width and length must be a valid numbers...";
}
if ($carpet == "") {
$bValid = false;
$strMessage = "$strMessage Carpet must be selected...";
}
if ($padding == "") {
$bValid = false;
$strMessage = "$strMessage Padding must be selected...";
}

if (isset($_GET['install']) == false) {
$bValid = false;
$strMessage = "$strMessage You must choose Installation or not";
$install = "";
}
else {
$install = $_GET['install'];
}

}
// if validation fails, set the vars to empty strings, display error message(s)

else {
$width = "";
$length = "";
$carpet = "";
$padding = "";
$install = "";

}
if ((count($_GET)==0)||($bValid ==false)){

if ($bValid==false){
print ("<div class='errorMsg'>$strMessage</div>");
}
}
?>
<body>
<div id="banner">
<h1>Zellers Carpeting</h1>
<h2>Cost Estimate</h2>
</div>
<div class="instructions">Enter all the relevant parameters and click submit for an estimate
of the cost of carpeting your room</div>

<img src = <?php // select image source, depending on the carpet selection
switch ($carpet) {
case "B":
print 'budget.jpg';
break;
case "S":
print 'standard.jpg';
break;
case "P":
print 'premium.jpg';
break;
case "":
print 'logo.jpg';
}
?> />

<div id="userinput">
<form method="get" name="frmInput" action="CarpetForm.php">
<table>
<tr>
<td><strong>Room Dimensions (in ft):</strong></td>
<td><input type=text name=width value="<?php print ("$width") ?>"> x <input type=text name=length value="<?php print("$length") ?>"></td>
</tr>
<tr>
<td ><strong>Type of Carpet:</strong></td>
<td>
<select name=carpet value = "<?php print ("$carpet") ?>">
<option value="">Choose Carpet Type</option>
<option value="B">Budget</option>
<option value="S">Standard</option>
<option value="P">Premium</option>
</select>
</td>
</tr>
<tr>
<td ><strong>Type of Padding:</strong></td>
<td>
<select name=padding value="<?php print ("$padding") ?>">
<option value="">Choose Padding</option>
<option value="S">Standard</option>
<option value="P">Premium</option>
</select>
</td>
</tr>
<tr>
<td><strong>Installation Required:</strong></td>
<td>Yes<input type=radio name=install value=y>&nbsp;&nbsp;&nbsp;No<input type=radio name=install value=n></td>
</tr>
<tr>
<td align=center colspan=2><input type="button" value="Submit"></td>
</tr>
</table>
</form>

</div>
<div id="estimate">

<?php
//perform calculations to figure the costs

$sqFoot = ($length * $width) * 1.2;
$L_W = ($length * $width);
$costCarpet = 0;
$costPad = 0;

switch ($carpet) {
case "B":
$costCarpet = $sqFoot * 1.00;
break;
case "S":
$costCarpet = $sqFoot * 1.50;
break;
case "P":
$costCarpet = $sqFoot * 2.00;
break;
}

switch ($padding) {
case "S":
$costPad = $sqFoot * .35;
break;
case "P":
$costPad = $sqFoot * .50;
break;
}

if (($install == "n") || ($install == "")) {
$costInstall = 0;
}
if ($install =="y") {
$costInstall = $L_W * 2.00;
}

$tax = ($costCarpet + $costPad) * .07;
$total = $costCarpet + $costPad + $costInstall + $tax;
$costCarpet = number_format($costCarpet,2);
$costPad = number_format($costPad,2);
$costInstall = number_format($costInstall,2);
$tax = number_format($tax,2);
$total = number_format($total,2);

//if all the data is present and is valid, diplay the final totals

if (count(($_GET)>0) && ($bValid == true) && ($sqFoot>0)) {
print ("<table cellpadding='2' cellspacing='2' border='1'>
<tr><th width='75'>Item</th><th width='75'>Estimate</th></tr>
<tr><td>Carpet: </td><td>$ $costCarpet</td></tr>
<tr><td>Padding:</td><td>$ $costPad</td></tr>
<tr><td>Installation: </td><td>$ $costInstall</td></tr>
<tr><td>Tax: </td><td>$ $tax</td></tr>
<tr><td>Total: </td><td>$ $total</td></tr>
</table>");
}
?>

</div>

</body></HTML>[/code]
Copy linkTweet thisAlerts:
@NogDogMay 07.2006 — Please read [url=http://www.webdeveloper.com/forum/showpost.php?p=546768&postcount=5]this item[/url] from this forum's [url=http://www.webdeveloper.com/forum/showthread.php?t=102044]F.A.Q.[/url], then update your posts accordingly.
Copy linkTweet thisAlerts:
@acetoneMay 08.2006 — That's strange...

It is working fine on my system... what version of php are you using?
Copy linkTweet thisAlerts:
@resullivanMay 08.2006 — stupid questions.

Is the name of the file *.php?

Does a basic php script work?

[code=php]
<?
print "test";
?>
[/code]
Copy linkTweet thisAlerts:
@disturbedspikeauthorMay 09.2006 — I updated the php version! Everything is coming up good now. Now, it's trying to get my code to print

Thanks you guys for the help.
×

Success!

Help @disturbedspike 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...