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 6715055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:34:07+00:00 2026-05-26T08:34:07+00:00

I’m writing my first php page for class. The page is supposed to take

  • 0

I’m writing my first php page for class. The page is supposed to take input from a form and output it. At first I tried to using the $content variable below to store a block of html which would output either the form or the ouput. I was putting this inside the id=”content” div depending on whether or not the form elements were set. Anyway, I moved away from this because I wasn’t able to use the _SERVER[‘PHP_SELF’] varialbe correctly. I’m abandoning this for now, but am now running into a similar problem. Here’ my code so far:

<?php

if (!empty($_POST['first-name']) && !empty($_POST['last-name']) 
    && !empty($_POST['age']))
{
    $fname = $_POST['first-name'];
    $lname = $_POST['last-name'];
    $age = $_POST['age'];

    $content = '<h1>About You</h1>
        <h4>First Name:</h4>
        <p><?php echo $fname; ?></p>
        <h4>Last Name:</h4>
        <p><?php echo $lname; ?></p>
        <h4>Age:</h4>
        <p><?php echo $age; ?></p>';
}
else
{
    $content = '';  
}

//get the first name, last name and age from the form


?>

<html lang="en">
<head>
    <title>Personal Info Results</title>
    <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
    <div class="content">
        <h1>My Form</h1>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <div id="person-info">
                <label>First Name:</label>
                <input type="text" name="first-name"/><br/>
                <label>Last Name:</label>
                <input type="text" name="last-name"/><br/>
                <label>Age:</label>
                <input type="text" name="age"/><br/>
            </div>
            <div id="submit"><input type="submit" value="Submit Info"/></div>
        </form>
    </div>
    <div id="output">
        <?php echo $content; ?>
    </div>
</body>
</html>

The problem right now is the fact that the echo function inside the $content variable isn’t causing the output to appear. Instead I’m getting blank lines. Am I defining it incorrectly inside of the String assignment?

  • 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-26T08:34:07+00:00Added an answer on May 26, 2026 at 8:34 am
    $content = '<h1>About You</h1>
        <h4>First Name:</h4>
        <p><?php echo $fname; ?></p>
        <h4>Last Name:</h4>
        <p><?php echo $lname; ?></p>
        <h4>Age:</h4>
        <p><?php echo $age; ?></p>';
    

    Should be

    $content = '<h1>About You</h1>
        <h4>First Name:</h4>
        <p>'.$fname.'</p>
        <h4>Last Name:</h4>
        <p>'.$lname.'</p>
        <h4>Age:</h4>
        <p>'.$age.'</p>';
    

    ECHO is not function and return nothing. Also you use <?php ?> construction inside PHP code. In this moment <h1>About You</h1> is not HTML, just string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.