everyxthing Posted March 9, 2006 Share Posted March 9, 2006 [!--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 2could 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--]<?PHPif ($_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> Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 9, 2006 Share Posted March 9, 2006 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 Link to comment Share on other sites More sharing options...
lessthanthree Posted March 9, 2006 Share Posted March 9, 2006 [!--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]<?phpif ($_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] Quote Link to comment Share on other sites More sharing options...
everyxthing Posted March 9, 2006 Author Share Posted March 9, 2006 okay thanks now it says line 23 has some thing wrong with it. Quote Link to comment Share on other sites More sharing options...
joecooper Posted March 9, 2006 Share Posted March 9, 2006 post the line 23 here Quote Link to comment Share on other sites More sharing options...
everyxthing Posted March 9, 2006 Author Share Posted March 9, 2006 [!--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> Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 9, 2006 Share Posted March 9, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.