View Full Version : newb needing help! ^_^
Shuichiro
03-11-2006, 02:45 AM
hello! I've tried this code and I cant find any errors but I keep getting this output after I try to enter the area code:
"Parse error: syntax error, unexpected $end in c:\Inetpub\wwwroot\shipping.php on line 28"
Youre suppossed to enter one of the area codes and then it spits out the shipping costs per area code.
Please, please, please help! please?
Main.php:
<html>
<head>
</head>
<body>
<form action="shipping.php" method="POST">
Enter your area code: <input type="text" name="areacode" />
<input type="submit" />
</form>
</body>
</html>
shipping.php
<html>
<head>
</head>
<body>
<?
if ($areacode = 508 || $areacode = 617 || $areacode = 413)
{
echo "Your shipping charges are $2.50 per pound";
} else {
if ($areacode = 207 || $areacode = 603 || $areacode = 802)
{
echo "Your shipping charges are $3.50 per pound";
} else {
if ($areacode = 404 || $areacode = 706 || $areacode = 803 || $areacode = 910 || $areacode = 804 || $areacode = 813 || $areacode = 407)
{
echo "Your shipping charges are $5.00 per pound";
} else {
if ($areacode = 614 || $areacode = 309 || $areacode = 314 || $areacode = 501 || $areacode = 515 || $areacode = 317 || $areacode = 606)
{
echo "Your shipping charges are $7.00 per pound";
} else {
echo "Your shipping charges are $11.00 per pound";
}
?>
</body>
</html>
blindmethod
03-11-2006, 05:27 AM
I believe your else statement syntax is the problem. I'm not as qualified as some of the other users, but here goes...
<?
if ($areacode = 508 || $areacode = 617 || $areacode = 413) {
echo "Your shipping charges are $2.50 per pound";
} elseif ($areacode = 207 || $areacode = 603 || $areacode = 802) {
echo "Your shipping charges are $3.50 per pound";
} elseif ($areacode = 404 || $areacode = 706 || $areacode = 803 || $areacode = 910 || $areacode = 804 || $areacode = 813 || $areacode = 407) {
echo "Your shipping charges are $5.00 per pound";
} elseif ($areacode = 614 || $areacode = 309 || $areacode = 314 || $areacode = 501 || $areacode = 515 || $areacode = 317 || $areacode = 606) {
echo "Your shipping charges are $7.00 per pound";
} else {
echo "Your shipping charges are $11.00 per pound";
}
?>
bustamelon
03-11-2006, 07:17 AM
Depending on the datatype of the $areacode variable, you might need to encapsulate those numbers in quotes.
<?
if ($areacode == "508" || $areacode == "617" || $areacode == "413") {
echo "Your shipping charges are $2.50 per pound";
} elseif ($areacode == "207" || $areacode == "603" || $areacode == "802") {
echo "Your shipping charges are $3.50 per pound";
} elseif ($areacode == "404" || $areacode == "706" || $areacode == "803" || $areacode == "910" || $areacode == "804" || $areacode == "813" || $areacode == "407") {
echo "Your shipping charges are $5.00 per pound";
} elseif ($areacode == "614" || $areacode == "309" || $areacode == "314" || $areacode == "501" || $areacode == "515" || $areacode == "317" || $areacode == "606") {
echo "Your shipping charges are $7.00 per pound";
} else {
echo "Your shipping charges are $11.00 per pound";
}
?>
You can also use switch():
<?
switch( $areacode ) {
case "508":
case "617":
case "413":
echo "Your shipping charges are $2.50 per pound";
break;
case "207":
case "603":
case "802":
echo "Your shipping charges are $3.50 per pound";
break;
case "404":
case "706":
case "803":
case "910":
case "804":
case "813":
case "407":
echo "Your shipping charges are $5.00 per pound";
break;
case "614":
case "309":
case "314":
case "501":
case "515":
case "317":
case "606":
echo "Your shipping charges are $7.00 per pound";
break;
default:
echo "Your shipping charges are $11.00 per pound";
break;
}
?>
Shuichiro
03-11-2006, 07:34 AM
The only problem I'm having now after trying those out (it fixed the error) but the "$2.50 per pound" response comes up for every area code that I enter.
Any ideas?
marek_mar
03-11-2006, 12:43 PM
You should use "==" in the if statements not "=".
Mhtml
03-11-2006, 01:15 PM
For every code? Odd... You're using the switch statement one? Have you modified it at all??
[edit:] Lol, nice and like marek_mar said... comparison not assignment melon/method!
bustamelon
03-11-2006, 03:39 PM
You should use "==" in the if statements not "=".
Right, sorry I missed that.
Shuichiro
03-11-2006, 03:45 PM
ok, when I used ethier the switch or the one before it, I get only the default answer, BUT it is also proceeded by:
"Notice: Undefined variable: areacode in c:\Inetpub\wwwroot\shipping.php on line 7"
and that appears for almost evert line.
Any suggestions?
bustamelon
03-11-2006, 03:54 PM
Well now, that's another story,
Where does $areacode come from? A form?
If this code gets processed as a result of a form post, you should first make sure a value is posting thru. So echo that $areacode at the top of your script (even though we already know it has no value).
If you aren't already doing it, you should make sure that you're adding a layer of abstraction between the global form var:
$areacode = $_POST['areacode'];
Chances are your problem is with the form. Paste that if you want.
Mhtml
03-11-2006, 03:54 PM
... The code on line 7 is?
Shuichiro
03-11-2006, 04:28 PM
mhtml, its not so much that the error is on line 7, an error appears like that for every # of values in each statement.
BUstamelon, both pages of code are posted in the top of this thread. Where would I want to put in the "$areacode = $_POST['areacode'];" ?
bustamelon
03-11-2006, 04:37 PM
BUstamelon, both pages of code are posted in the top of this thread. Where would I want to put in the "$areacode = $_POST['areacode'];" ?
Whoops, right. Duh.
Here: make shipping.php look like this:
<html>
<head>
</head>
<body>
<?
if ( isset( $_POST['areacode'] )) {
$areacode = $_POST['areacode'];
if ($areacode == "508" || $areacode == "617" || $areacode == "413") {
echo "Your shipping charges are $2.50 per pound";
} elseif ($areacode == "207" || $areacode == "603" || $areacode == "802") {
echo "Your shipping charges are $3.50 per pound";
} elseif ($areacode == "404" || $areacode == "706" || $areacode == "803" || $areacode == "910" || $areacode == "804" || $areacode == "813" || $areacode == "407") {
echo "Your shipping charges are $5.00 per pound";
} elseif ($areacode == "614" || $areacode == "309" || $areacode == "314" || $areacode == "501" || $areacode == "515" || $areacode == "317" || $areacode == "606") {
echo "Your shipping charges are $7.00 per pound";
} else {
echo "Your shipping charges are $11.00 per pound";
}
}
?>
</body>
</html>
Shuichiro
03-11-2006, 04:51 PM
Bustamelon, you hit the nail on the head! Perfect!:thumbsup:
Thanks to everyone that contributed! Now I can go study for finals in peace.
Mhtml
03-12-2006, 01:06 AM
mhtml, its not so much that the error is on line 7, an error appears like that for every # of values in each statement.
Well actually that is precisely the problem. You weren't initializing the areacode variable before testing it. Thus that-
$areacode = $_POST['areacode']; would also have been a solution to the problem.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.