0

hi

i am trying to, on a button click, display data retrieved from mysql database in a text area but having no success. Below is the code i used. All help given is appreciated

print "<center><TEXTAREA NAME=news ID=news COLS=70 ROWS=10>".$news."</TEXTAREA></center>";

if(isset($_POST['show2'])){
		$cn = connect_db();
		$cn_sql = "SELECT message from messageboard";
		$con_res = mysql_query($cn_sql);
		$news = $con_res;
6
Contributors
5
Replies
11
Views
7 Years
Discussion Span
Last Post by php_dev
0

PHP is not a language you can use to modify a page's content after it has been loaded on the client side.

To do this you might want to try AJAX but i'm no real expert with it.

Otherwise, you could figure out something with an iframe where you would load a php script querying the mysql database and then retrieving its content with javascript but that's far fetch I believe.

1

hi

i am trying to, on a button click, display data retrieved from mysql database in a text area but having no success. Below is the code i used. All help given is appreciated

print "<center><TEXTAREA NAME=news ID=news COLS=70 ROWS=10>".$news."</TEXTAREA></center>";

if(isset($_POST['show2'])){
		$cn = connect_db();
		$cn_sql = "SELECT message from messageboard";
		$con_res = mysql_query($cn_sql);
		$news = $con_res;

Hi,,
we can write as....


<textarea name="txt_addr" >
<?php echo $rows["address"]; ?>
</textarea>

0

Ajax is the way to do this. You need to send the form to a php script with ajax and then have it return the data to the textarea.

Here is a simple ajax request to get you started:

function ajaxHandler(endParams, returnId)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try
		{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} 
	catch (e)
		{
			// Internet Explorer Browsers
			try
				{
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} 
			catch (e) 
				{
					try
						{
							ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
						} 
					catch (e)
						{
							// Something went wrong
							alert("Your browser broke!");
							return false;
						}
				}
		}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
				{
					document.getElementById(returnId).innerHTML = ajaxRequest.responseText;
				}
		}
	
	ajaxRequest.open("GET", "pageThatProcessesRequest.php" + endParams, true);
	ajaxRequest.send(null); 
}

then you just add an 'onclick='ajaxHandler("?getVar=something", "idToReturnDataTo");' to the button and it will return the data to the id that matches 'idToReturnDataTo' as .innerHTML (may not be the best for textareas, if theres a problem change the .innerHTML to .value .

Edited by xylude: oops needed double quotes somewhere.

0

How does this SQL work?
did you try doing var_dump($news);

cn = connect_db();
		$cn_sql = "SELECT message from messageboard";
		$con_res = mysql_query($cn_sql);
		$news = $con_res;

Assuming that you wrote your own db connect somewhere and it is correct,
Your out put is a mysql resouce, an probably an array since you are selecting message which will return ALL of the messages.
the resource needs to be passed into:

$news = mysql_fetch_array($con_res);

which will convert this into a PHP readable array that can be read out.
If connect_db(); is calling the php mysql functions and is connecting to a selected database, then all you need to do is call it;:

connect_db();

I think you should review all of the MySQl related code as well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.