p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   MySQL (http://p2p.wrox.com/forumdisplay.php?f=99)
-   -   Display data in textarea with select statement (http://p2p.wrox.com/showthread.php?t=12215)

Alex_forever April 23rd, 2004 06:08 PM

Display data in textarea with select statement
Here is basically what I have. I'm trying to query the database to display in a textarea so that I can update the information while looking at it could someone please help me with this topic
$Id = $_GET['Id'];

$query = "SELECT Code FROM AddTable2 WHERE Id = '$Id'";
$result = @mysql_query ($query) or die;
if ($result)

Message: <textarea name = "message" rows = "20" cols = "80" wrap = "virtual" value = "<?php echo "$result"; ?>" /></textarea><br>

P.S I am only a beginner so please excuse the messy code writing

Snib April 23rd, 2004 06:45 PM

A few things are wrong with your code. One thing is that mysql_query() returns an identifier, not a readable value. Let me write a script for you as an example:


//standard connect to database

$query = "SELECT Code FROM AddTable2 WHERE Id='$Id'";
$result = mysql_query($query);
$data = mysql_fetch_assoc($result);
<textarea><?php echo $data['Code']; ?></textarea>




Alex_forever April 23rd, 2004 07:01 PM

It's saying "query was empty". But I copied and past the select statement, from a previous file that worked, on to the code. Do you think it's a parsing issue

Snib April 23rd, 2004 07:09 PM

Oops, I messed up on my last code. I have corrected it. Try it again and tell me if it works.



Alex_forever April 23rd, 2004 07:12 PM

For those who didn't reply or didn't know here is some information for you:
This is how you do it
if (isset($_GET['Id']) && !is_null($_GET['Id']))
    $Id = $_GET['Id'];

$query1 = "SELECT Code FROM AddTable2 WHERE Id = '$Id'";
$result1 = @mysql_query ($query1) or die (mysql_error());
$data = mysql_fetch_assoc($result1);
if ($result1)

Message: <textarea name = "Code" rows = "20" cols = "80" wrap = "virtual"><?php echo str_replace("<", "&lt;", $data['Code']); ?></textarea><br>

nikolai April 27th, 2004 05:55 PM

Using htmlentities() is a cleaner solution to using str_replace() on all left brackets.

echo "<textarea>" . htmlentities($data['code'] . "</textarea>\n";

This prevents the text area from being incorrectly terminated when the data you're printing in the textarea containst the text "</textarea>".

Take care,


Snib April 27th, 2004 06:05 PM

So that no one gets confused, I think Nik meant to say this:

echo "<textarea>" . htmlentities($data['code']) . "</textarea>\n";

Excuse me for correcting you, Nik. Is this what you meant?




All times are GMT -4. The time now is 07:52 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.