Jump to content

Newbie having problems with print


Recommended Posts

Ok, I'm newbie and am having some problems! At first I was having problems getting page to view correctly, updated the php version, all is good there.
I don't know if I have fudged up my code, but when I enter values on the page and click the button, there is nothing that is being printed back to me....



<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> 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>
Link to comment
https://forums.phpfreaks.com/topic/9363-newbie-having-problems-with-print/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.