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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:51:03+00:00 2026-05-18T06:51:03+00:00

My dilemma is this: I have a PHP page with a form that includes

  • 0

My dilemma is this: I have a PHP page with a form that includes a textarea where the user can enter any kind of text. The code below is at the top part of my PHP page, to check whether or not the user has pressed the “Submit” button for the form, and to error-check all the user input:

<?php 
// check if user has pressed the Submit button earlier
if (isset($_POST['submit'])) {
    ...
    $loc = mysqli_real_escape_string($dbc, trim($_POST['location']));
    ...

The code below is the HTML/PHP code for the form, and the textarea specifically:

...
// location texarea entry
echo '<label for="location">Meeting location: </label><br />';
echo '<textarea name="location" id="location" cols="40" rows="5">' . htmlentities($loc) . '</textarea><br />';

// submit button
echo '<input type="submit" value="Submit" name="submit"/><br />';
...

When I enter, let’s say:

Testing testing...

...

<>// HELLO!!!

Into the textarea, but then fail one of the other checks on the page so the form/page is refreshed and shows an error, I want to retain what the user wrote in the textarea. But with the code I have, the stored text that is displayed turns into:

Testing testing...\r\n\r\n...\r\n\r\n<>// HELLO!!!

How can I “save” the textarea contents so it is identical to what the user wrote before the PHP page is refreshed? Can’t think of a solution. 🙁 Many thanks in advance!

  • 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-18T06:51:03+00:00Added an answer on May 18, 2026 at 6:51 am

    You should echo the original $_POST['location'] value (with htmlentities), not the trimmed and mysql_real_escaped version of it.

    $loc = null;
    if (/* POST */) {
        $loc = $_POST['location'];
        ...
        $query = 'INSERT INTO ... "' . mysql_real_escape_string(trim($loc)) . '"';
        ...
    }
    
    echo '<textarea name="location" id="location" cols="40" rows="5">' . htmlentities($loc) . '</textarea><br />';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this dilemma. I'm developing a web services. It has to return a
I have this dilemma with JavaScript. I need to convert a list of dates
May be some one has had similar experiences on this dilemma and can help
Here is my dilemma... I basically have a script which by means of CURL
I have this question on and of for a year or two, but it
I have a fairly complicated function that takes several double values that represent two
I'm creating my own blog in PHP and want to know your opinions on
I have a method where I am passing in two object, which have the
sorry for the unclear title but I couldn't come up with anything better. My

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.