Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
| Search | Today's Posts | Mark Forums Read
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2004, 06:08 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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




 
Old April 23rd, 2004, 06:45 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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:
Code:
<?php

//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>
HTH,

Snib

<><
 
Old April 23rd, 2004, 07:01 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old April 23rd, 2004, 07:09 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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

Snib

<><
 
Old April 23rd, 2004, 07:12 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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'];
else
    exit('fail');

$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>
 
Old April 27th, 2004, 05:55 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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,

Nik
http://www.bigaction.org/
 
Old April 27th, 2004, 06:05 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

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?

HTH,

Snib

<><




Similar Threads
Thread Thread Starter Forum Replies Last Post
select either textarea or radiobutton pavani ASP.NET 2.0 Basics 1 March 21st, 2008 04:35 AM
change content of textarea from select darkhalf Javascript 1 April 26th, 2007 06:03 AM
Display text data in textarea from SQL query palvin Classic ASP Professional 13 November 30th, 2005 05:52 PM
Display text data in textarea from SQL query palvin Classic ASP Databases 0 November 29th, 2005 05:44 PM
display vbCrLf's from textarea to textarea mat41 Classic ASP Basics 8 June 10th, 2004 12:19 AM





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