Forum Moderators: coopster

Message Too Old, No Replies

How do i get Mysql data into a textarea?

Requested data from database does not show up in textarea

         

dbzfyam

5:30 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



Yet another question. I am trying to create a script to display the data from a MySQL database in seperate textfields and textareas (so that the user can then edit the page and update the database). Everything works fine when I place the data in normal text fields. However, when I try to do the same with a textarea to display the html stored in the database, the script does not display anything (Only a empty texarea). Can someone help me with this (I think I still have to learn quite a lot about PHP)? Here is the code I have so far:

<?php
session_start();
$slogin_noauthpage = 0;
$slogin_pagetitle = "Edit Page";
include_once("slogin_lib.inc.php");
include_once("header.inc.php");
include_once("database.php");

if (isset($_REQUEST['id']))
{$idnumber = $_REQUEST['id'];}
else {die ("Could not retreive neccesary data");}

if (isset($_REQUEST['page']))
{$pagename = $_REQUEST['page'];}
else {die ("Could not retreive neccesary data");}

mysql_connect($dbhost,$dbuser,$dbpass) or die ("Couldn't connect to database");
mysql_select_db($dbname) or die ("Couldn't select database");
$query = "SELECT * FROM content WHERE ID='$idnumber' AND Page='$pagename'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

echo "<table width=\"90%\" border=\"0\" cellpadding=\"4\" align=\"center\" class=\"onder\">\n";
echo "<tr>\n";
echo "<td align=\"center\"><font class=\"uppertext\" size=\"-2\"><b>EDITING PAGE \"{$row['Page']}\" WITH ID \"{$row['ID']}\".</font></b></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td bgcolor=\"#838383\">\n";
echo "<form method=\"POST\" action=\"editPageUpdate.php\">\n";
echo "<center>Page Name:<br><input cols=\"45\" type=\"text\" value=\"{$row['Page']}\" name=\"Page\"></center><br>\n";
echo "<center>Link Name:<br><input cols=\"45\" type=\"text\" value=\"{$row['Link']}\" name=\"Link\"></center><br>\n";
echo "<center>Page Content:<br><textarea value=\"{$row['Content']}\" name=\"Content\" rows=\"15\" cols=\"90\"></textarea></center>\n";
echo " <center><input type=\"reset\"> <input type=\"submit\" name=\"submit\" value=\"Submit\"></form>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table><BR>\n\n";
echo "<center>To edit the author or category of a page, click on Edit above.</center>\n\n";
?>

maxi million

6:15 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



try this
echo "<center>Page Content:<br><textarea name=\"Content\" rows=\"15\" cols=\"90\">".$row['Content']."</textarea></center>\n";

dbzfyam

6:42 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



Thank you very much maxi million! It works perfectly now.

coopster

3:11 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Also, don't forget to really scrub that incoming HTML data that you are allowing. If they dropped a chunk of PHP code in there, is it going to parse? Are you allowing them to run javascript? Just be careful what you are allowing your end users to do. If you want them to simple use bold or italics, etc, then make sure that is the only tags you are allowing to go into your database table.

dbzfyam

3:56 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



That shouldn't be a problem since this script is for the 'add/edit page' (so the webmaster should be able to use all the html/javascript/php etc) for my CMS (It's a quite simple CMS but it does the job. About 45kb so far) which is only accesible by the webmaster. The only problem is that I don't know if the pages are protected properly. I found a premade script which uses sessions to secure the admin panel (I don't know anything about sessions or protecting scripts, since I just started with PHP). I hope it's safe..

PS: I did use strip_tags() for the comment boxes to only allow <b>, <i> and <u>. But does this remove all the HTML and PHP etc (With other words, can someone insert and run malicious code even when strip_tags() is applied)?