[SOLVED] retrieving value from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

[SOLVED] retrieving value from database

Post 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]
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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>';
?>
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

yes it worked....thanks....but in the case of textareas....i believe that there is no value property, what can i do??
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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>';
?>
Post Reply