0

I have been tasked with creating a PHP quiz and have ran into some error when trying to make it a SPA (Single Page Application). The known way I've been shown to do this is by wrapping your HTML code within an echo" " function but when doing so i get a parse error for one line that tries to loop back on itself to produce a results section i have once the submit button is pressed on the page after all questions is answered.

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /opt/lampp/htdocs/SPA/index.php on line 186


Note i have this function working when ran as an individual separate page but no luck when trying to turn that page into a function within my index.php to turn it all into one SPA (As that's my end goal)

Line producing the error above:

<form name="inputForm" id="inputForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validateForm()">

Submit button which checks the answers

if(isset($_POST["submit"])){
checkAnswers();
}

My output should be the results from my quiz but my current output is the error noted above.

user3783243
  • 5,368
  • 5
  • 22
  • 41
  • That seems valid, are you already in PHP though? Also that is XSS injectable. If you are echoing `
    – user3783243 Apr 11 '19 at 16:12
  • @user3783243 **EDIT** Okay so i done what you said and i got the page to load and got rid of the error.
    That was my solution incase you see any flaws within it that might add to my next problem, my next issue is that now its still now showing the results and instead bouncing me to the start of index.php, instead of going to my submit and checkAnswers() method as seen above
    – Thomas Mortell Apr 11 '19 at 16:27
  • See https://stackoverflow.com/questions/6080022/php-self-and-xss for the injection issue. For your other issue I'm not sure but that's a different question. I think this should be closed as the syntax dup. – user3783243 Apr 11 '19 at 17:34

0 Answers0