0

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  
}  
?>
4
Contributors
5
Replies
14
Views
6 Years
Discussion Span
Last Post by gunnerone
1

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.

Votes + Comments
helpful
0

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
0

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

shouldn't that be description?

1
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";
//}
}
?>
Votes + Comments
Very helpful
0

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

This question has already been answered. 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.