html checkbox MySQL help please :)
Posted: Tue Dec 12, 2006 2:25 am
Hi Guys,
I have never messed with html checkboxes and php before and I am a bit stuck.
Here is what I am doing.
I am dynamically creating the html checkboxes from a MySQL table like this
This then lists all the available modules, the user then has to check all the boxes they want and click next.
All the bixes that have been checked and posted to the next page I need to insert into the MySQL database.
Can anyone tell me how I would do this.
I looked at
Which lists all the checked modules but I don't know where to go from here.
Thanks.
I have never messed with html checkboxes and php before and I am a bit stuck.
Here is what I am doing.
I am dynamically creating the html checkboxes from a MySQL table like this
Code: Select all
<?php session_start();
include_once("../includes/connection.php");
$myuser_name = $_SESSION['myuser_name'];
$listModules = mysql_query("SELECT
id,
user_name,
module_name,
module_path
FROM modules_user WHERE user_name = '$myuser_name'")
or die(mysql_error());
if(mysql_affected_rows()==0){
echo 'There is no modules available for you to grant!';
}
echo '<ul>';
while ($line = mysql_fetch_array($listModules))
{
extract($line);
echo '<li><input name="'.$module_name.'" type="checkbox" id="'.$module_name.'" value="'.$module_name.'" /> <strong>'.$module_name.'</strong></li>';
}
echo '</ul>';
?>
All the bixes that have been checked and posted to the next page I need to insert into the MySQL database.
Code: Select all
INSERT INTO modules_company //This is where I am stuck
I looked at
Code: Select all
<?php
foreach ( $_POST as $key => $val )
{$key}: {$val}
?>
Thanks.