I have a form which looks like, I wanted to be able to collect the cells values for form processing:
<form method ="post" action="sendmail.php">
<table>
<h4>Orders</h4>
<tr>
<th>Order Number</th>
<th>Order Date</th>
<th>Ordered By</th>
<th>Supplier</th>
<th>Total Price</th>
<th>Requested By</th>
<th>Status</th>
<th>Send Notification</th>
</tr>
<?php
while($row=mysql_fetch_array($result)){
echo "</td><td>";
echo $row['Orderno'];
echo "</td><td>";
echo $row['Orderdate'];
echo "</td><td>";
echo $row['Orderedby'];
echo "</td><td>";
echo $row['Supplier'];
echo "</td><td>£ ";
echo $row['totalprice'];
echo "</td><td>";
echo $row['requestedby'];
echo "</td><td>";
echo ' <select name="status">
<option></option>
<option>Approved</option>
<option>Pending</option>
<option>Dissaproved</option>
</select>';
echo "</td><td>";
echo '<input type="submit" value="Send Email" />';
echo "</td></tr>";
}
echo "</table>";
?>
</form>
My question is how can I retrieve the values in each cell, to use for form processing? With these values I will create an email template to email a person. For example something like $to = $_POST['requestedby'];
I have tried using POST
to no avail.
Well you're first problem is that you are not storing the variables you are taking out from your database anywhere, you are just printing them, so when you click Send Email the only thing you are sending to sendmail.php is the select name="status".
Store your results into normal variables so that you can have them available in all your page like this:
then proceed to fill out your table like this:
And now so you can store the variables in your form do the following:
I believe having the submit button before these inputs isn't a problem but if it is just write the last bit before the submit button and you'll be good.
Hope this helped!
usualy i use this way
the on sendmail.php i just make some modification
I may have changed your logic as the HTML is not valid. In addition, it was not necessary to make several submit buttons because there is only one form :
EDIT : If you really want one button per row, you will have to make one in row, which is possible only with nested tables (
<tr>
doesn't allow<form>
inside it). I think it will be too complex.So, I kept a unique form and submit button and I add a checkbox to each row so you will select one (or more) orders to send email(s).
After, in PHP, you can retrieve all these informations with this :