inserting records when multiple check box is selected
Posted: Sat Sep 26, 2009 6:08 am
Hi,
i have bug when inserting records into mysql when multiple check boxes are selected
i have created a master table groups with 2 columns group_id & group_name to this groups i have created a sub_groups table where group_id is the foreign key and 2 more columns sub_group_id & sub_group_name when i select the group check box test the sub_group table has the records where the group_id refers, and remaining values should be inserted but im getting the error as
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\new.php on line 27
i have bug when inserting records into mysql when multiple check boxes are selected
Code: Select all
<?php
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
<input type="checkbox" name="id[]" value="1" />Test<br />
<input type="checkbox" name="id[]" value="2" />Business<br />
<textarea name="txt" rows="10" cols="30"></textarea>
<select name="ddl" id="" class="text">
<option value="select">select</option>
<option value="TM-TEST">TM-TEST</option>
</select>
<input type="submit" value="submit" name="submit">
</form>
<?php
} else {
mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error());
mysql_select_db("smsdb");
$media_array = $_POST['media'];
foreach ($media_array as $one_media) {
$source .= $one_media.", ";
}
$media = substr($source, 0, -2);
$query = "INSERT INTO group_sms(group, message, sender_id)
VALUES( '$media','$_POST[txt]','$_POST[ddl]')";
$result = mysql_query($query);
}
?>
</body>
</html>Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\new.php on line 27