Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:19:36+00:00 2026-05-26T11:19:36+00:00

I am pretty new to php world. I wrote the following: <html> <head> <title>It

  • 0

I am pretty new to php world. I wrote the following:

<html>
<head>
    <title>It joins simple1 and prac1 program together</title>
</head>
<body>
    <?php
        if($_POST['user'])
        {
            print "hello,";
            print $_POST['user'];
        }
        else{
        print <<<_HTML_
            <form method="post" action="$_server[PHP_SELF]">
                Your name:<input type="text" name="user">
                </br>
                <input type="submit" value="hello"> 
            </form>
        _HTML_;
        }           
    ?>
</body>
</html>  ---- line 23

Getting Error message:

Parse error: syntax error, unexpected $end in C:\wamp\www\php_practice\simple2.php on line 23

I have removed all html tags and just kept php tags it worked:

<?php
// Print a greeting if the form was submitted
if ($_POST['user']) {
print "Hello, ";
// Print what was submitted in the form parameter called 'user'
print $_POST['user'];
print "!";
} else {
// Otherwise, print the form
print <<<_HTML_
<form method="post" action="$_SERVER[PHP_SELF]">
Your Name: <input type="text" name="user">
<br/>
<input type="submit" value="Say Hello">
</form>
_HTML_;
}
?>

Output : Giving proper output but with an warning

Notice: Undefined index: user in C:\wamp\www\php_practice\test.php on line 3
  1. Why it is not working with the previous case? What is going wrong?

  2. How to remove or silent the warning message in the second code. It looks bad in the browser.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:19:36+00:00Added an answer on May 26, 2026 at 11:19 am

    The cause of your parse error:

    The closing of a HEREDOC statement must occur at the beginning of a line with no whitespace before or after. You have your _HTML indented to the same level as the rest of your code, but it must occur at the very first character position of the line.

        _HTML_;
    
    // Should be
    _HTML_;
    

    The cause of your undefined index warning:

    To test if $_POST['user'] is set, use isset(). That will take care of your undefined index error.

    if(isset($_POST['user']))
    

    Update: The cause of the undefined variable _server notice:

    Inside a HEREDOC or double quoted string, you will need to wrap complex variables (arrays, objects) in {}. Also, place quotes around PHP_SELF.

    <form method="post" action="{$_SERVER['PHP_SELF']}">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to the world of web developing and web design in PHP,
I am pretty new to php, but I am learning! I have a simple
I am pretty new to PHP and I am trying to make an inventory
I've done a fair bit of mysql php programming but am pretty new to
I'm pretty proficient in PHP, but want to try something new. I'm also know
I'm working on a new project, using Apache's mod_rewrite and PHP to get pretty
I'm pretty new to php but i'm learning pretty fast, I have a question
I'm new to ASP.NET and to SQL Server. I'm from the PHP/MySQL world, so
I'm pretty new to OOP (and also in PHP programming), and I have some
I'm pretty new to PHP and MySQL. I'm interested in setting up a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.