Jump to content


Photo

I need help with php.


  • Please log in to reply
6 replies to this topic

#1 everyxthing

everyxthing
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 09 March 2006 - 07:44 PM

[!--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...ml4/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...ml4/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>



#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 09 March 2006 - 07:46 PM

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

#3 lessthanthree

lessthanthree
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts
  • LocationUK

Posted 09 March 2006 - 07:59 PM

[!--quoteo(post=353357:date=Mar 9 2006, 07:46 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 9 2006, 07:46 PM) View Post[/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]


<?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']);
?>


better still:

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"; 
}

call me a safe bet, i'm betting i'm not

#4 everyxthing

everyxthing
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 09 March 2006 - 08:37 PM

okay thanks now it says line 23 has some thing wrong with it.

#5 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 09 March 2006 - 09:09 PM

post the line 23 here
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#6 everyxthing

everyxthing
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 09 March 2006 - 09:13 PM

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



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


#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 March 2006 - 11:38 PM

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.

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

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users