I wonder if someone could point me in the right direction.
I have a simple table tbl_friends with just 2 fields:
friend_id
first_name
I have a page called checkbox.php which contains 3 checkboxes (Tom, Dick and Harry) and one submit button. When I check Tom and Harry then click Submit I would like the firstname field to add 2 new records, namely Tom and Harry to the first_name field (friend_id is just an autonumber primary key).
I just can't figure out the syntax to make this happen. I believe i want to create a checkbox array hence the square braces [] but i don't understand what that means - i just read it.
When I click the Submit button, the friend_id field is auto-incrementing so i know the connection to the database and query string is ok.
Code below:
<?php
require_once('mysqli_connect.php');
if (isset($_POST['submitted'])){
$fn=trim($_POST['first_name']);
$q1="INSERT INTO tbl_friends (first_name) VALUE ('$fn')";
$r=mysqli_query($dbc,$q1);
if ($r) {
echo '<h1>Data Sent OK</h1>';
}
mysqli_close($dbc);
exit();
}
?>
<form action="checkbox.php" method="post">
Tom <input type="checkbox" name="friends[]" value="<?php echo $POST['first_name'];?>"/>
Dick <input type="checkbox" name="friends[]" value="<?php echo $POST['first_name'];?>"/>
Harry <input type="checkbox" name="friends[]" value="<?php echo $_POST['first_name'];?>"/>
<input type="submit" value="Submit"/>
<input type="hidden" name="submitted" value="TRUE"/>
</form>