After posting on the General board and getting a vague reply - "Your Form is Wrong" I thought that maybe i should have posted on the coding forum instead.
Please bear with me as i'm fairly new to PHP
I have a simple mysql table tbl_friends consisting of two fields: friends_id (an autonumber primary key) and first_name (varchar)
The following is my attempt at trying to get a checkbox array consisting of 3 names Tom, Dick and Harry to INSERT into the table.
So if the user checks Tom and Harry say, these names will be inserted into the first_name field. When I click the Submit button, the values aren't being inserted into the first_name field. I'd greatly appreciate any help - ideally if you could load up the code for my page checkbox.php (shown below) and try creating the simple table i mention.
I've read so many posts on this and other forums - been trying for 3 days now - I'm tired and I need to complete this for a work-based project!
p.s. I know that i'm connecting to the database ok as i'm able to insert from a text box into a column on another table
<?php
require_once('mysqli_connect.php');
$fn=trim($_POST['first_name']);
foreach($_POST['first_name'] as $fn) {
$q1="INSERT INTO tbl_friends (first_name) VALUES ('$fn')";
mysqli_query($dbc,$q1);
}
?>
<html>
<body>
<form method="post" action="checkbox.php">
<input type="checkbox" name="first_name[]" value="Tom"> Tom <br />
<input type="checkbox" name="first_name[]" value="Dick"> Dick <br />
<input type="checkbox" name="first_name[]" value="Harry"> Harry <br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>