I want to pull 2 fields from a MySQL database and them use them in 2 hidden form fields along with allowing the user to input data into additional form fields. I am using the following code to do so:
$yesterday = date('d/m/Y',strtotime("-1 days"));
$sql="SELECT acct_backup_servers.server_desc, acct_customer.customer from acct_backup_servers, acct_customer
where acct_backup_servers.cust_act=acct_customer.acct_no ";
$result=mysql_query($sql);
echo '<form action="http://www.bimotech.co.uk/admin/insert_backup_rec/index.php" method="post">
<table>
<tr>
<th width="20%" align="left" valign="top">Server</th>
<th width="20%" align="left" valign="top">Customer</th>
<th align="left" valign="top">Date</th>
<th width="25%" align="left" valign="top">Status</th>
<th width="30%" align="left" valign="top">Notes</th>
<th align="left" valign="top"></th>
</tr>';
while($rows=mysql_fetch_array($result)){
$server_notes = $rows['server_desc'];
echo "
<input type='hidden' name='server' value='".$rows['server_desc']."'>
<input type='hidden' name='customer' value='".$rows['customer']."'>
<tr>
<td valign='top'>".$rows['server_desc']."</td>
<td valign='top'>".$rows['customer']."</td>
<td valign='top'><input type='text' name='date' size='10' id='datepicker' value='".$yesterday."'></td>
<td valign='top'>
<select name='status'>";
$sql2 = mysql_query("SELECT cat_desc FROM acct_backup_category");
while ($row = mysql_fetch_array($sql2)){
echo "<option value='category'>" . $row['cat_desc'] . "</option>";
}
echo "</select></td>
<td valign='top'><textarea name='notes'></textarea></td>
<td valign='top'><input type='checkbox' name='completed'></td>
</tr>";
}
echo "</table>
</br>
<input type='submit' class='btn' value='Submit'>
</form>";
mysql_close();
I have setup the page that this form post to and echo'd the results but all I am receiving is the last record. Is there a way that I can get all the results for each row and post them in one go to the database?
EDIT: PHP Echo below.
$backup_date = $_POST['date'];
$server_desc = $_POST['server'];
$customer = $_POST['customer'];
echo $backup_date;
echo $server_desc;
echo $customer;
I am very much a PHP newbie so appreciate anyones help on this.
Further EDIT:
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
foreach($customer as $key => $value) {
$date = $backup_date[$key];
$server = $server_desc[$key];
$customer_id = $value;
$backup_code = $status[$key];
$notes_field = $notes[$key];
$been_checked = $checked[$key];
mysql_query("INSERT INTO acct_backups (backup_date, server_code, cust_act, backup_code, notes, checked) VALUES ($date, $server, $customer_id, $backup_code, $notes_field, $been_checked)");
}
mysql_close();
Thanks,
John