I currently have a form where I can subscribe and unsubscribe users from newsletters wich looks like this:
The code for the bottom part (the subscriptions part) is this:
<?php
$i = 0;
while($objResult1 = mysql_fetch_array($objQuery1))
{
$i++;
?>
<tr>
<td><div align="center"><?=$objResult1["ID"];?><input type="hidden" name="mailid" value="<?=$objResult1["ID"];?>"> </div></td>
<td><div align="center"><?=$objResult1["Titel"];?> </div></td>
<td><div align="center"><input type="checkbox" name="sub" value="10"> </div></td>
<td><div align="center"><input type="checkbox" name="sub" value="90"> </div></td>
</tr>
<?php
}
?>
And the code to insert the values into the database is this:
<?php
mysql_connect('localhost','root','root');
mysql_select_db('NAW') or die (mysql_error());
$Klant_ID = $_POST['klantid'];
$Mail_ID = $_POST['mailid'];
$Status = $_POST['sub'];
$Datum = date("d-m-Y");
$sql = mysql_query(
"INSERT INTO Subscriptions (
Klant_ID,
Mail_ID,
Status,
Datum
) VALUES (
'".$Klant_ID."',
'".$Mail_ID."',
'".$Status."',
'".$Datum."'
)"
);
if ($sql === false) {
die (mysql_error());
} else {
echo 'Je gegevens zijn succesvol in de database geplaatst.<br><br>Om de gegevens uit de database te bekijken klik <A HREF="klanten.php">hier</A>. <br>Om meer gegevens in te voeren klik <A HREF="index.html">hier</A>.';
}
?>
The database is:
ID Klant_ID Mail_ID Status Datum
1 6 1 test
2 6 1 test test
3 10 10 10 19-03-13
16 6 4 90 20-03-2013
17 6 4 10 20-03-2013
18 7 4 90 20-03-2013
Now it will just add 1 row to the database where I checked a checkbox. I want to get it working so it will add 3 rows to the database, for example:
When I select the boxes like this:
I want these rows to be added to the database:
ID Klant_ID Mail_ID Status Datum
20 6 1 10 20-03-2013
21 6 2 90 20-03-2013
22 6 4 10 20-03-2013
So my question is if this is posible using a while loop with mysql_fetch_array? I am not a pro in php cause I'm still a student and I can't solve this problem on my own. I hope my question is clear enough but if you have any question just ask in the comments^^ If anyone can show me how it is done or push me in the right direction it would be great!
(I know I shouldn't be using mysql_* anymore but that is not the point here^^)