+ 2

Can someone tell me what's wrong in this code?

I'm a beginner and I want to make a calculator sort of thing through which I can show the fuctioning of some logical operators in PHP. But I'm myself confused about what should be done. Please help!! https://code.sololearn.com/wukv4R9bm6YN/?ref=app Notice: Undefined variable: result in ./Playground/file0.php on line 42

23rd Sep 2020, 11:47 AM
Sanwali Sood
Sanwali Sood - avatar
3 Answers
+ 2
Hey, Thanks a lot for helping and I tried doing what you said but still I didn't get any better results...🙁 I hope this problem will be sorted out soon!
23rd Sep 2020, 4:08 PM
Sanwali Sood
Sanwali Sood - avatar
+ 1
You are displaying <$result> at line 42 while the form data processing is done from line 46. I suggest you to move the PHP code from line 46 ~ 66 up to the beginning of document before any other code, and setup a default value for <$result> when there is no form data submission.
23rd Sep 2020, 12:43 PM
Ipang
+ 1
You're not running this in SoloLearn right? coz it won't work in SoloLearn. if(isset($_POST['submit'])) { // PHP code here } else { $result = 0; // default value when form isn't submitted } Remove case 'None' from switch statement block and use default: label instead. BTW, you forgot to add 'break' for case 'None'.
23rd Sep 2020, 4:52 PM
Ipang