By mademarest on
I'm getting the following errror when I try to add my first php form into a page:
Parse error: parse error, unexpected ';' in /home/videofit/public_html/includes/common.inc(1175) : eval()'d code on line 4
here's the code I'm using from a tutorial for creating a simple calculator:
<?php
if ((isset($_POST["done"])) && ($_POST["done"] =="y")) (
$height = ((12 * $_POST["feet"]));
if ((isset($_POST["inches"])) && ($_POST["inches"] = 0)) (
$height = $height + $_POST["inches"];
)
$bmi = ($_POST["lbs"] / ($height * $height)) * 703;
)
?>
<p>BMI Calculator</p>
<form method="post" name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>"
<table width="180" border="1" cellspacing="2" cellpadding="0">
<tr>
<td><strong>Details</strong></td>
<td></td>
<td></td>
</tr>
<tr>
<td><strong>Height</strong></td>
<td><input type="text" name="feet" value="" size="5" maxlength="2" /></td>
<td>feet</td>
</tr>
<tr>
<td></td>
<td><input type="text" name="inches" value="" size="5" maxlength="2" /></td>
<td>inches</td>
</tr>
<tr>
<td>Weight</td>
<td><input type="text" name="lbs" value="" size="5" maxlength="3" /></td>
<td>pounds</td>
</tr>
<tr>
<td><input type="submit" name="Calculate" value="Calculate" /><input type="hidden" name="done" value="y"></td>
<td bgcolor="#3c6fac"><? echo $bmi; ?></td>
<td bgcolor="#3c6fac"><strong>your BMI</strong></td>
</tr>
</table>
Comments
-edited-
erp! corrected below by another user, who knew better then I.
You didn't close off your if
You didn't close off your first if statement block. Also - unless it's just my eyes - you seem to be using parentheses instead of curly braces for your statement blocks ... I don't think that's valid.
Try changing it to:
---
http://www.whatwoulddrupaldo.org
you guys rock...now
thanks so much!
now the form works, but...
when I hit the 'calculate' button,
instead of displaying the results,
it bumps me to the homepage.
any advice?
thanks for helping a newbie.
Try changing
Try changing $_SERVER['PHP_SELF'] to base_path().$_REQUEST['q'];
However, this probably isn't really the right way to handle these things. Drupal has a Forms API (http://api.drupal.org/api/HEAD/file/developer/topics/forms_api.html) to handle these types of things. But you might be able to get around it by making the above change.
---
www.whatwoulddrupaldo.org
sure enough...
...it worked!
thanks again.
Now, just so I know, why isn't this the best way to handle it? What did we do?
In the meantime, I'll spend the first half of today studying the api link you sent.
much appreciated!
- Mark
www.8-weeks.com
(under construction)