Hi

I am trying to populate a text area based on a value submitted through a drop down box. Below is the code i have written to populate that text area. But i cannot seem to get it to work. All it shows is blank.

<?php
if (!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Email'])) {
?>
 
<p><form method="post" action="">
<fieldset>
<table width="558" border="0" cellpadding="5">
<tr>
<td><label for="recipe">Recipe:</label></td>
<td><SELECT NAME="recipeid"><OPTION VALUE=0>Select Recipe<?php echo $item; ?></SELECT>
</td>
</tr>
</table>
<input type="submit" id="login-submit" value="Register" />
</fieldset>
</form></p> 
                       
<?php
if(!empty($_POST['recipeid'])){
$recipeid = mysql_real_escape_string($_POST['recipeid']);
$description = mysql_query("SELECT decription FROM recipes WHERE recipeid = '" . $recipeid . "'");
echo'<textarea rows="10" cols="75">';
echo $description; 
echo '</textarea>';}?>
           
<?php
}
else {
?>
<p> Please login to view this content</p>               
<?php  
}  
?>

A mysql_query returns a resource, not a string. So after your query you can use mysql_fetch_array to get to your description. See the manual for examples.

commented: helpful +2

Thanks for the reply. I have tried using the method you gave above, but i am getting this error when i submit the form:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given
Member Avatar for diafol

SELECT decription FROM recipes WHERE recipeid = '" . $recipeid . "'"

shouldn't that be description?

if(!empty($_POST['recipeid'])){
$recipeid = mysql_real_escape_string($_POST['recipeid']);
$mysqlResult = mysql_query("SELECT decription FROM recipes WHERE recipeid = '" . $recipeid . "'");
$mysqlArray = mysql_fetch_assoc($mysqlResult);//if the query should be 1 row

echo'<textarea rows="10" cols="75">';
echo $mysqlArray['decription'];//the fieldname from the mysql query, it's missing an s is that a typo?
echo '</textarea>';

//while($mysqlArray = mysql_fetch_assoc($mysqlResult)){//if theres more than 1 row loop through each row
//echo'<textarea rows="10" cols="75">'.$mysqlArray['decription'].'</textarea>'."\r\n";
//}
}
?>
commented: Very helpful +1

Thanks, yeah it looks like there was some typos. Thanks for your help, much appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.