PHP script
Hello all,
I am trying to write a script in PHP. A simple calculator! (Just learning PHP)
anyways,
I think my code is fine (I think)but I still get the following error:
Parse error: parse error, unexpected $ in /home/virtual/site2/fst/var/www/html/calculate.php on line 33
Can someone help me out to figure out the problem? I am running this code off my servers that is supposed to have PHP installed.
Thanks
here is the code:
<?
if (($val1=="") || ($val2=="") || ($calc=="")) {
header("Location: http://www.sefati.com/test.html");
exit;
if ($calc=="add")
{
$results=$val1+$val2;
}
else if ($calc=="subtract")
{
$results=$val1-$val2;
}
else if ($calc=="multiply<")
{
$results=$val1*$val2;
}
else if ($calc=="divide")
{
$results=$val1/$val2;
}
?>
Calculation Results
The result of calculation is: <? echo "$result"; ?>
mrbinaryking posted this at 03:41 — 26th December 2003.
They have: 10 posts
Joined: Dec 2003
k found it
my syntax
did not close the bracket for if statemetn
m3rajk posted this at 20:55 — 28th December 2003.
They have: 461 posts
Joined: Jul 2003
just something for you to consider: speed and efficiency. if this isn't something where you're calculating something that you store based on user input, it's faster to use javascript.
php is very strong, but there are times when it's not the best tool for the job. any calculating you don't need to store, chances are javascript is better.
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
ROB posted this at 18:14 — 29th December 2003.
They have: 447 posts
Joined: Oct 1999
a word of advice, don't get in the habit of relying on register_globals. fetch your query info yourself:
<?php
$val1 = &$_GET['val1'];
$val2 = &$_GET['val2'];
$calc = &$_GET['calc'];
?>
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.