Page 1 of 1

[SOLVED] retrieving value from database

Posted: Thu Mar 17, 2005 2:03 am
by pleigh
i have an edit page here....i want to do is when i click edit, i want the value, for example, the topic of the message will also appear in the textfield...to further explain, i am also confused to what i'm saying.. :)

if the topic of my message is "first repprt".....i want to change the topic to "first report"...so i will click the edit link....in my edit link, instead of a blank textfield, i want the wrong topic(in this case, the "first repprt") to appear inside the textfield, so that i will only edit part of the mistake instead of the whole topic....

so far, here's my code

Code: Select all

<?
		  $query = &quote;SELECT topic FROM posts WHERE postID = '$eid'&quote;;
		  $result = @mysql_query($query);
		  
		  echo 	'<tr>
		  		<td width=&quote;20%&quote; align=&quote;right&quote;><b>TOPIC</b></td>
				<td width=&quote;1%&quote;><b>:</b></td>
				<td width=&quote;79%&quote;><input name=&quote;topic&quote; style=&quote;width:350px&quote; type=&quote;text&quote; value=&quote;{$row&#1111;0]}&quote; size=&quote;40&quote; maxlength=&quote;40&quote;></td>
		  		</tr><br>';
		  
		  ?>
by the way, this code returns
{$row[0]}
to the value of the textfield [/quote]

Posted: Thu Mar 17, 2005 2:09 am
by infolock
try this instead :

Code: Select all

<?php
$sql = mysql_query("SELECT topic FROM posts WHERE postID = '".$eid."'") or die(MySQL_Error());
$row = mysql_fetch_assoc($sql) or die(MYSQL_Error());  //i use fetch_assoc for everything >:)
echo '<tr>
	    <td width="20%" align="right"><b>TOPIC</b></td>
		<td width="1%"><b>:</b></td>
		<td width="79%">
			<input name="topic" style="width:350px" type="text" value="'.$row['topic'].'" size="40" maxlength="40">
		</td>
		</tr>
		<br>';
?>

Posted: Thu Mar 17, 2005 2:34 am
by pleigh
yes it worked....thanks....but in the case of textareas....i believe that there is no value property, what can i do??

Posted: Thu Mar 17, 2005 2:50 am
by infolock
you could do something like this :

Code: Select all

<?php
echo '<textarea name="product_desc" rows="10" cols="35" wrap="virtual" style="width:425px">'.$row['prod_desc'].'</textarea></td>';
?>