Why and where my php code gives error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why and where my php code gives error

I making validation but in between my code gives error anyone help me why this error shows and how to solve https://code.sololearn.com/wEu6OpNJ7a02/?ref=app https://code.sololearn.com/wEu6OpNJ7a02/?ref=app https://code.sololearn.com/wEu6OpNJ7a02/?ref=app

13th Jul 2020, 5:05 PM
Coder
Coder - avatar
9 Answers
+ 3
There are a few problems with it. Problem 1: JavaScript in CSS style element alert("help me why this error comes"); That isn't valid CSS. If you want that as a comment in HTML, use <!-- --> and don't put it in a style element. If you want that to execute as JavaScript, put it in a script element. Problem 2: Typo in closing head tag </heaf> should be </head> This is minor but you should fix it. Problem 3: Bad space characters Inconsistent and invalid spacing. Sololearn's Code editor makes this clear by marking them with dots. The characters aren't tabs, line breaks, or regular spaces and are invalid for PHP. Make sure the brackets balance properly and try to consistently indent with all tabs or all space characters. Fixing those issues should get your code working somewhat. Submitting the form won't work in Sololearn's Code Playground but submitting should work locally. $_SERVER['REQUEST_METHOD'] also won't work in Code Playground but will be accessible locally or on one of your personal servers.
14th Jul 2020, 12:34 AM
Josh Greig
Josh Greig - avatar
+ 1
Josh Greig thanks for reply
14th Jul 2020, 3:40 AM
Coder
Coder - avatar
+ 1
Hi Josh I indent it properly as in pc but now error is again change to unexpected error of ';' on line 13. Now what should I do
16th Jul 2020, 4:15 AM
Coder
Coder - avatar
0
You're welcome, Adesara. I checked just now and see that you fixed problems 1 and 2 but still not 3. The dots still show in Sololearn's editor.
14th Jul 2020, 11:48 AM
Josh Greig
Josh Greig - avatar
0
Adesara, you should look at it in Sololearn's code editor. The problem becomes obvious there. Problem 3 is still a problem around your if-statements on lines 11 and 12 between the if and (. Look at it in Sololearn's code editor and you'll see dots instead of spaces. Using notepad++ and probably a lot of other editors won't show the dots because you have weird characters that show differently depending on the font family. When I try in notepad++ it LOOKS like regular spaces because the font family just draws nothing for it.
16th Jul 2020, 1:23 PM
Josh Greig
Josh Greig - avatar
0
Thanks my big bro for supporting me.
16th Jul 2020, 2:34 PM
Coder
Coder - avatar
0
I solved now it shows of request _method error. What should I do next
16th Jul 2020, 2:35 PM
Coder
Coder - avatar
0
The original answer explained what you're up to now: Submitting the form won't work in Sololearn's Code Playground but submitting should work locally. $_SERVER['REQUEST_METHOD'] also won't work in Code Playground but will be accessible locally or on one of your personal servers. It is a limitation of Sololearn's Code Playground. If you really want similar behaviour in Sololearn's playground, you'll have to work around the limitation. You'll have to convert your PHP for processing the POST parameters to JavaScript like this: <!Doctype html> <html lang="en"> <head> <title>Name Validator</title> <script> function getMessage() { if (getSanitizedName() === '') { return 'enter'; } else { return 'right'; } } function getSanitizedName() { return document.querySelector('[name=name]').value.trim(); } function onSubmit() { document.getElementById('nerr').innerText = getMessage(); document.getElementById('sanitized-name').innerText = getSanitizedName(); return false; // Return false to prevent the form from actually submitting and sending an HTTP POST request. } </script> </head> <body> <form onsubmit="return onSubmit()" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>"> <label>Name :</label> <input type="text" name="name"> <span id="nerr"></span> <input type="submit" value="submit"> </form> <div id="sanitized-name"></div> </body> </html>
16th Jul 2020, 5:08 PM
Josh Greig
Josh Greig - avatar
0
Ok thanks .😊😊
18th Jul 2020, 6:13 AM
Coder
Coder - avatar