0

I ran my code through the validator but ran into this:

Parse error: syntax error, unexpected '$age' (T_VARIABLE) in CODE on line 4
Errors parsing CODE

I'm very new to php.

From my research people have said that the problem is a wrong placement of the "[/]" or ";" but i think that's all good so what is going wrong?

I can also post the html and js in case that is necessary.

<?php
    $firstName = $_GET['firstName'];
    $lastName = $_GET['lastName'];
    $age = $_GET['age'];
    $email = $_GET['email'];
    echo "<h2>Response Demo Form</h2><h3> ";
    echo "You submitted the following information<br><ul>";
    echo "<li>Name: <strong> $firstName $lastName</strong></li>";
    echo "<li>Age: $age</li>";
    echo "<li>Age: $email</li>";
    echo "</li></ul></h3>";
?>
let firstName = document.getElementById("firstName");
let lastName = document.getElementById("lastName");
let age = document.getElementById("age");
let email = document.getElementById("email");
let submitButton = document.getElementById("submitButton");
let responseHere = document.getElementById("responseHere");

submitButton.addEventListener('click', ajax);

function ajax(){
  let xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function(){
    if (this.readyState == 4 && this.status == 200){
      responseHere.innerHTML = this.responseText;
  }
};
let httpString = "form_1.php?firstName=" + firstName.value + "&lastName=" + lastName.value + "&age=" + age.value + "&email=" + email.value;

console.log(httpString);

xmlhttp.open("GET", httpString, true);
xmlhttp.send();
}

<!DOCTYPE html>
<html>
  <head>
        <meta charset="utf-8">
        <meta name="author" content="Lucas Baneke GD1A">
        <title>Ajax form_1</title>
  </head>
  <body>
        <h2>Form_2</h2>
        <form>
            <input type = "text"  id = "firstName" name = "firstName" placeholder = "voornaam">
      <input type = "text"  id = "lastName" name = "lastName" placeholder = "achternaam">
            <input type = "text"  id = "age" name = "age" placeholder = "leeftijd">
      <input type = "text"  id = "email" name = "email" placeholder = "email">
      <input type = "button" id = "submitButton" value = "submit">
        </form>
    <div id = "responseHere">hier komt de response</div>
    <script src="script.js"></script>
  </body>
</html>

Error:Parse error: syntax error, unexpected '$age' (T_VARIABLE) in CODE on line 4

Errors parsing CODE

Shaw358
  • 23
  • 6

1 Answers1

1

This can occur if there's a weird invisible character before line 4. You can remove the invisible characters by opening the file in something like sublime text that allows you to view invisible characters.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140