Jump to content

Archived

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

everyxthing

I need help with php.

Recommended Posts

[!--coloro:#CC33CC--][span style=\"color:#CC33CC\"][!--/coloro--]OK so I am a college student who is going to school for web design and we are learning like php and my sql and all that stuff. I was doing my home work and its like we have to make a calculation thing and when I got done with I got a Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in F:\Students\redulac\javascript\hwweek6\calculate.php on line 2


could some one please tell me where I went wrong and help me fix it.


here is the code and then the one after that is whats calling it [!--colorc--][/span][!--/colorc--]

<?PHP
if ($_POST['vall' =="";] || ($_POST 'val2' =="" || ($_POST 'calc' ==)) {header("Location: calculate_form.html");
exit;
}
if ($_POST['calc' == "add"]{$result = $_POST['vall' + $_POST['val2'])
elseif ($_POST['calc' =="subtract"]{$result = $_POST['vall'- $_POST]['val2'])
elseif ($_POST['calc' =="mutiply"]{$result = $_POST['vall' * $_POST['val2'])
elseif ($_POST['calc' =="divide"]{$result = $_POST['vall' / $_POST['val2'])
?>




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Calcuation</title>
</head>

<body>
The result of the calcuation is <?php echo"$_
result"; ?>;
</body>
</html>




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Calculation Form</title>
</head>

<body>
<form action="calculate.php" method="post">
<p> Value 1:
<input name="vall" type="text" id="vall" size="10">
</p>
<p> Value 2:
<input name="val2" type="text" id="val2" size="10">
</p>
<p> Calculation</p>

Add</p>
<p><input name="calc" type="radio" value="add"></p>
<br> <p><input name="subtract" type="radio" value="subtract">
subtract </p>
<p><input name="multiply" type="radio" value="multiply">multiply</p>
<p> <input name="divide" type="radio" value="divide"> divide</p>
<p> <input type="submit" name="Submit" value="Calculate"></p>


</form>

</body>
</html>

Share this post


Link to post
Share on other sites
Your bracketing is all wrong. The correct way to access form input is $_POST['val1'] or $_POST['calc'], etc. Yours are all horribly disfigured.

Share this post


Link to post
Share on other sites
[!--quoteo(post=353357:date=Mar 9 2006, 07:46 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 9 2006, 07:46 PM) [snapback]353357[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Your bracketing is all wrong. The correct way to access form input is $_POST['val1'] or $_POST['calc'], etc. Yours are all horribly disfigured.
[/quote]


[code]
<?php
if ($_POST['vall'] == "" || $_POST['val2']  == "" || $_POST['calc'] == "") header("Location: calculate_form.html");
if ($_POST['calc'] == "add") $result = ($_POST['vall'] + $_POST['val2']);
elseif ($_POST['calc'] == "subtract") $result = ($_POST['vall'] - $_POST['val2']);
elseif ($_POST['calc'] == "mutiply") $result = ($_POST['vall'] * $_POST['val2']);
elseif ($_POST['calc'] =="divide") $result = ($_POST['vall'] / $_POST['val2']);
?>
[/code]


better still:

[code]
switch($_POST["calc"])
{
    case("add"):
        $result = ($_POST["val1"] + $_POST["val2"]);
    break;
    
    case("subtract"):
        $result = ($_POST["val1"] - $_POST["val2"]);
    break;  
    
    case("multiply"):
        $result = ($_POST["val1"] * $_POST["val2"]);
    break;
    
    case("divide"):
        $result = ($_POST["val1"] / $_POST["val2"]);
    break;
    
    default: $result = "No calulation method provided";
}
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=353388:date=Mar 9 2006, 03:09 PM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Mar 9 2006, 03:09 PM) [snapback]353388[/snapback][/div][div class=\'quotemain\'][!--quotec--]
post the line 23 here
[/quote]



<body>
The result of the calcuation is
<?php echo"$_result ?>
</body>
</html>

Share this post


Link to post
Share on other sites
It doesn't say "something is wrong", it gives you some very specific message .... that helps you understand what the problem might be. Those help people here answer your question.

[code]<body>
The result of the calcuation is
<?php echo $result; ?>
</body>
</html>[/code]

Share this post


Link to post
Share on other sites

×

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.