I am trying to retrieve a value from mysql and put it into an Area box with php and I have been having some trouble's I wouldn't know how to go about this I would really appriciate some help. So far I have just made the textarea and retrieve and echo the query I want to be able to put the text from the query into the text area and be able to edit the text and then re submit it to the database. I can do the rest I just need to know how to get the query into the Textarea. Any help?

Dani AI

Generated

As pointed out, the visible value simply comes from your query result being placed inside the textarea. For a reliable, safe edit-and-resubmit flow there are a few important things to add after that one-liner: escape output for HTML, preserve/newline handling, use modern DB APIs, validate input on submit, and protect against CSRF and SQL injection.

Escape the text before inserting into HTML so characters like <, > and & don’t break the page or create XSS risks. Use htmlspecialchars with ENT_QUOTES and the correct charset (UTF-8) when echoing into form fields (see htmlspecialchars). Do not run nl2br before placing text in a textarea — the textarea displays raw newlines, so convert only if you need an HTML view elsewhere.

Normalize newlines from the DB if users come from different platforms:

$body = str_replace("\r\n", "\n", $body_from_db);

On submit, use prepared statements (PDO or mysqli) to update the database and avoid the deprecated mysql_* API. A compact PDO example:

$stmt = $pdo->prepare('UPDATE items SET content = ? WHERE id = ?');
$stmt->execute([$postedContent, $id]);

See PDO prepared statements for details: PDO prepared statements.

Also validate length and content server-side, store long text in TEXT/MEDIUMTEXT as needed, set your DB connection charset to utf8mb4, and include CSRF protection on the edit form. These steps turn the quick fix that offered into a secure, maintainable solution for and future readers.

Recommended Answers

All 2 Replies

Member Avatar for Member #120589
<textarea><?php echo $output;?></textarea>

Put the relevant db output into the $output variable - do all this above the DTD and then simply echo it out inside the textarea. Simple.

Thanks sometimes all you need is a little direction figured it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.