errors and errors

Reply

Join Date: Jul 2007
Posts: 8
Reputation: drastic is an unknown quantity at this point 
Solved Threads: 0
drastic drastic is offline Offline
Newbie Poster

errors and errors

 
0
  #1
Apr 4th, 2008
i made a form with 2 input buttons(for taking number inputs) and 4 radio buttons(add sub mul and divide) and one submit button(calculate) to make a simple calculator and wrote a php script which takes input values and and according to the button selected do the operation but when i run this in browser and give values , select the required button it gives a list of errors about unused radio buttons (like if i select sub then at all the rest add mul and divide buttons it gives error) and in the last line shows correct answer, wha's this?

here is the code ofr script
  1. <?php
  2. if (($_POST[vall] == "") || ($_POST[val2] == "") || ($_POST[calc] ==""))
  3. { header("Location: http://127.0.0.1/calculate_form.html");
  4. exit;
  5. }
  6. if ($_POST[calc] == "add") {
  7. $result = $_POST[vall] + $_POST[val2];
  8. }
  9. else if ($_POST[calc] == "subtract") { $result = $_POST[vall] - $_POST[val2]; }
  10. else if ($_POST[calc] == "multiply") { $result = $_POST[vall] * $_POST[val2]; }
  11. else if ($_POST[calc] == "divide") { $result = $_POST[vall] / $_POST[val2]; }
  12.  
  13. ?>
  14. <HTML>
  15. <HEAD>
  16. <TITLE>Calculation Result</TITLE>
  17. </HEAD>
  18. <BODY>
  19. <P>The result of the calculation is: <? echo "$result"; ?></P>
  20. </BODY>
  21. </HTML>
------------------------------------------------------------------
this one for form
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Calculation Form</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <FORM METHOD="POST" ACTION="calculate.php">
  7. <P>Value 1: <INPUT TYPE="text" NAME="vall" SIZE=10></P>
  8. <P>Value 2: <INPUT TYPE="text" NAME="val2" SIZE=10></P>
  9. <P>Calculation:<br>
  10. <INPUT TYPE="radio" NAME="calc" VALUE="add"> add<br>
  11. <INPUT TYPE="radio" NAME="calc" VALUE="subtract"> subtract<br>
  12. <INPUT TYPE="radio" NAME="calc" VALUE="multiply"> multiply<br>
  13. <INPUT TYPE="radio" NAME="calc" VALUE="divide"> divide</P>
  14.  
  15. <P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></P>
  16. </FORM> </BODY> </HTML>
-----------------------------------------------------
and this one the error list
Notice: Use of undefined constant vall - assumed 'vall' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 2

Notice: Use of undefined constant val2 - assumed 'val2' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 2

Notice: Use of undefined constant calc - assumed 'calc' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 2

Notice: Use of undefined constant calc - assumed 'calc' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 6

Notice: Use of undefined constant vall - assumed 'vall' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 7

Notice: Use of undefined constant val2 - assumed 'val2' in d:\backup data\data a\a\miscallaneous data\ebooks\web languages\myphp\test\calculate.php on line 7

The result of the calculation is: 3
---------------------------------------------------------------
if any one could help me i dont want this error list before the answer
Last edited by peter_budo; Apr 5th, 2008 at 1:33 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 570
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: errors and errors

 
0
  #2
Apr 4th, 2008
Please post your code.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: errors and errors

 
0
  #3
Apr 4th, 2008
Notices are not errors. You can get rid of notices by initializing a variable before using it.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 129
Reputation: hacker9801 is on a distinguished road 
Solved Threads: 15
hacker9801 hacker9801 is offline Offline
Junior Poster

Re: errors and errors

 
0
  #4
Apr 4th, 2008
yeah, 'vall' isn't a constant - you need to change it to $vall and declare it before.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 8
Reputation: drastic is an unknown quantity at this point 
Solved Threads: 0
drastic drastic is offline Offline
Newbie Poster

Re: errors and errors

 
0
  #5
Apr 4th, 2008
thanx it's done by simply putting val in double quotes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 639 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC