Jump to content

Wiernusz

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Wiernusz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Well that may be, but I think you are saving the wrong file. The code I posted should not produce any notice errors. My 2cents, you are saving the wrong file. Here is the code I tested on my server, with no notice errors etc. <?php error_reporting(E_ALL); ini_set("display_errors", 1); if (!isset($_POST['submit']) || ($_POST['val1'] == "") || ($_POST['val2'] == "") || ($_POST['calc'] == "")) { header("Location: calculate_form.php"); exit; } if ($_POST['calc'] == "add") { $result = $_POST['val1'] + $_POST['val2']; $what = " plus "; } else if ($_POST['calc'] == "subtract") { $result = $_POST['val1'] - $_POST['val2']; $what = " minus "; } else if ($_POST['calc'] == "multiply") { $result = $_POST['val1'] * $_POST['val2']; $what = " times "; } else if ($_POST['calc'] == "divide") { $result = $_POST['val1'] / $_POST['val2']; $what = " divided by "; } echo 'My calculations returned: ' . $_POST['val1'] . $what . $_POST['val2'] . " = " . $result; ?> Which returned: My calculations returned: 2 plus 3 = 5 It seems as you were typing this, I edited my previous post... I did end up getting it working with your previous post. Thanks alot! It did work For the most part, I see what was wrong, and it's weird the publisher hadn't mentioned it. But to say the least - the book has been the best one yet (no throwing in stuff and not telling me about it!). Considering how much I've learned here compared to a whole bunch of other places, I decided I will finish this book. Helping me fix that code taught me a few things, and props to you for taking time to help me out here. You rock!
  2. Hey, thanks for posting the working script. I really appreciate it! :-)
  3. Considering I am a PHP beginner, and this book is telling me to do things the wrong way (from the looks of it)... I am just going to scratch this whole thing, because I am just plain lost. One thing I would really like to know though, is the completed code for this to actually work so I can review it, and not have these past few hours of learning be a waste. If anyone is willing to show me the working script with no Notices/errors, I would be a happy person (for now!) Again, thanks for the help everybody.
  4. Thanks for all the quick replys guys. It's appreciated. I am starting to think this book I am following is out-dated or just plain wrong. Still trying to get it to work following all of your advice.
  5. Hello. I am currently following a tutorial on building a simple calculator. Here is my calculation code: <?PHP if (($_POST[val1] == "") || ($_POST[val2] == "") || ($_POST[calc] == "")) { header("Location: calculate_form.php"); exit; } if ($_POST[calc] == "add") { $result = $_POST[val1] + $_POST[val2]; } else if ($_POST[calc] == "subtract") { $result = $_POST[val1] - $_POST[val2]; } else if ($_POST[calc] == "multiply") { $result = $_POST[val1] * $_POST[val2]; } else if ($_POST[calc] == "divide") { $result = $_POST[val1] / $_POST[val2]; } ?> And here is my form code: <html> <head> <title>Calculation Form</title> </head> <body> <font size="3" face="verdana"> <FORM METHOD="post" ACTION="calc.php"> <P>Value 1: <INPUT TYPE="text" NAME="val1" SIZE=10></P> <P>Value 2: <INPUT TYPE="text" NAME="val2" SIZE=10></P> <P>Calculation:<br> [<INPUT TYPE="radio" NAME="calc" VALUE="add"> <b>+</b> ] [<INPUT TYPE="radio" NAME="calc" VALUE="subtract"> - ] [<INPUT TYPE="radio" NAME="calc" VALUE="multiply"> <b>*</b> ] [<INPUT TYPE="radio" NAME="calc" VALUE="divide"> <b>/</b> ]</P> <P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></P> </FORM> </body> </html> It apparently works, but it also gives me these warnings, along with the correct math answer; Notice: Use of undefined constant val1 - assumed 'val1' in E:\wamp\www\Learning\Calculator\calc.php on line 2 Notice: Use of undefined constant val2 - assumed 'val2' in E:\wamp\www\Learning\Calculator\calc.php on line 2 Notice: Use of undefined constant calc - assumed 'calc' in E:\wamp\www\Learning\Calculator\calc.php on line 2 Notice: Use of undefined constant calc - assumed 'calc' in E:\wamp\www\Learning\Calculator\calc.php on line 6 Notice: Use of undefined constant calc - assumed 'calc' in E:\wamp\www\Learning\Calculator\calc.php on line 8 Notice: Use of undefined constant val1 - assumed 'val1' in E:\wamp\www\Learning\Calculator\calc.php on line 9 Notice: Use of undefined constant val2 - assumed 'val2' in E:\wamp\www\Learning\Calculator\calc.php on line 9 I've put this together using a PHP 5 tutorial from a book, and have gone over it 4 times to make sure I havn't missed anything. Any help/tips would be greatly appreciated. Thanks in advance!
×
×
  • Create New...

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.