I have a database table with user info: name, email and item they committed to donate. I'd like to display what item they own on the web page, so I've constructed this query:
$email = (isset($_POST['email'])) ? $_POST['email'] : '';
$i = "SELECT required_items.name
FROM required_items LEFT JOIN donations ON donations.item_id=required_items.id
WHERE donations.email = '" .$email. "' ";
$ir = $db->query($i);
$rows = $ir->fetchAll();
foreach($rows as $data){
$item_name = $data['name'];
}
Then later when I display the info:
<tr>
<td><label>Item</label></td>
<td><input type="text" name="name" value="<?php echo $item_name; ?>"></td>
</tr>
When I run the query and replace ".$email." with an email address, the query works correctly and I am able to see their donation in phpmyadmin, but as of right now with this variable in the code I only get something that just says Array.
How can I display the correct information? I eventually want it sent to the user via email so this would be very helpful.
EDIT: I've applied the advice given by STLMikey and now the $item_name displays "NULL".