Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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




Reply With Quote
  #2 (permalink)  
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

<><
Reply With Quote
  #3 (permalink)  
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

Reply With Quote
  #4 (permalink)  
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

<><
Reply With Quote
  #5 (permalink)  
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>
Reply With Quote
  #6 (permalink)  
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/
Reply With Quote
  #7 (permalink)  
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

<><
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:26 AM.


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