-4

error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\html\updatedtimeline.html on line 109

Im getting this error in my code and i would like to understand why? Thanks for any help

i want to add the email of the user logged in my html element

<h6 id="myemail">  </h6>

line 109:

echo "<script> document.getelementById('myemail').value= $_SESSION['email'] </script>";
menna
  • 41
  • 1
  • 10

1 Answers1

1

Try following:

<?php session_start();?>

    <h6 id="myemail">  </h6>

    <?php
        echo "<script> document.getElementById('myemail').innerHTML = '{$_SESSION['email']}'; </script>";
    ?>

Please make sure that your echo should be placed after <h6 id="myemail"> </h6> is printed out.

Please pay attention to the order of the code. You should make sure <h6 id="myemail"> </h6> is printed already before you echo script code.

Codemole
  • 3,069
  • 5
  • 25
  • 41
  • I've made this changes and im getting a debug error `Uncaught TypeError: Cannot set property 'value' of null` – menna Jan 07 '17 at 13:23
  • then your `$_SESSION['email']` is not set – bansi Jan 07 '17 at 13:28
  • @menna `Uncaught TypeError: Cannot set property 'value' of null` should be happening in javascript console, correct? I have updated the code. Check it out. – Codemole Jan 07 '17 at 13:31
  • @bansi To check the value of my ` $_SESSION['email']` i tried `echo "welcome " . $_SESSION['email'];` and i got `welcome iahmedwael@gmail.com` (Which shows that my value of session is correct) and my html element has an id myemail as the following `
    `
    – menna Jan 07 '17 at 13:31
  • @RayC my code was changed accordingly to ` document.getElementById('myemail').innerHTML = '{$_SESSION['email']}'; "; ?>` and im getting a debug error `Uncaught TypeError: Cannot set property 'innerHTML' of null` – menna Jan 07 '17 at 13:33
  • @menna As I mentioned in my answer, please make sure you have `
    ` already printed before you do `echo` thing. My suggestion is, you move `echo` thing to the last part of your code, so that make `
    ` is already printed.
    – Codemole Jan 07 '17 at 14:10