0

I have this code, but I'm getting

Parse error: syntax error, unexpected '<<' (T_SL) on line 48

I think the problem is from php code. but, i don't know what is it. Can someone please explain why this error, or what my script is missing?

Thanks.

<!DOCTYPE html>
<html>
    <head>
        <!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
        <script>
            function updatemenu() {
                if (document.getElementById('responsive-menu').checked == true) {
                    document.getElementById('menu').style.borderBottomRightRadius = '0';
                    document.getElementById('menu').style.borderBottomLeftRadius = '0';
                    }else{
                    document.getElementById('menu').style.borderRadius = '9px';
                }
            }
        </script>
    </head>
    
    <body>
            <div id="content">
                <center><br><br>
                        <?php
                            $uid=<<<EOD 
                                ID : $_POST['user_id']
                            EOD;
                            $upw=<<<EOD 
                                PW : $_POST['user_pw']
                            EOD;
                            
                            echo $uid; 
                            echo $upw; 
                        ?>
                </center><br><br><br><br>
            </div>
    </body>
</html>
김다빈
  • 3
  • 1
  • **That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon** https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc – user3783243 Apr 05 '21 at 16:03
  • Does this answer your question? [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – user3783243 Apr 05 '21 at 16:04
  • This also would open you to XSS injections and I don't know when a password would ever be outputted. – user3783243 Apr 05 '21 at 16:05

2 Answers2

0

I think you have blank space after EOD, when there should be none. Please remove it and retry. Also remove any proceeding blank space before the ending EOD;

enter image description here

Solution: Remove trailing space after ALL <<<EOD and remove preceding whitespace before ALL the terminating EOD;

enter image description here

Rakesh Gupta
  • 3,507
  • 3
  • 18
  • 24
  • THX for your help. But, when i remove blank space after EOD there's another error. Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) on line 46 – 김다빈 Apr 05 '21 at 16:10
  • Did you also remove the space before the terminiating EOD; ? – Rakesh Gupta Apr 05 '21 at 18:50
0

While you could use HEREDOC it poses an issue when it comes to spaces as another answer already points out. The way that I would approach it is to use something like the following which works and is easier to read:

<center><br><br>
    ID: <?php echo $_POST['user_id']; ?>
    PW: <?php echo $_POST['user_pw']; ?>
</center>

Reflecting the user's password back to them on the page isn't advised unless you are just getting a feel for how data moves around pages.

hppycoder
  • 1,016
  • 1
  • 6
  • 13