So, I am very new to PHP and am trying to get this code to work but get the following error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/masterch/public_html/hofstra/ppu_ballpointpen.php on line 47
Here is the code:
<?php
function CalculatePPU($Quantity)
{
switch($Quantity)
{
case ($Quantity<=150): //Quantity <150
return 0.55;
break;
case ($Quantity<=250): //Quantity 151-250
return 0.48;
break;
case ($Quantity<=500): //Quantity 251-500
return 0.52;
break;
default: //Quantity >500
return 0.40;
break;
}
}
if(!empty($_GET['Quantity']))
{
if(ctype_digit($_GET['Quantity']))
{
$PPU= CalculatePPU($_GET['Quantity']);
$TP= $_GET['Quantity']*$PPU;
}
else
$PPU= 'Quantity must be a positive integer.';
}
?>
<html>
<head>
<title>
Price Per Unit Calculator
</title>
</head>
<body>
<form method='GET' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
<table>
<tr>
<td>
Quantity:
</td>
<td>
<input type='text' name='Quantity'<?php echo (isset($_GET['Quantity']))?' value=''.$_GET['Quantity'].''':''; ?>></input>
</td>
</tr>
<tr>
<td>
Price Per Unit:
</td>
<td>
<b><?php echo (isset($PPU))?$PPU:'Not calculated yet.'; ?></b>
</td>
</tr>
<tr>
<td>
Total Price:
</td>
<td>
<b><?php echo (isset($TP))?$TP:'Not calculated yet.'; ?></b>
</td>
</tr>
<tr>
<td colspan='2'>
<input type='Submit' value='Calculate PPU'></input>
</td>
</tr>
</table>
</form>
</body>
</head>
I know this isn't the most complex of problems so any help would be greatly appreciated.