html checkbox MySQL help please :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

html checkbox MySQL help please :)

Post by ianhull »

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

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.'" />&nbsp;&nbsp;<strong>'.$module_name.'</strong></li>';
}
echo '</ul>';
?>
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.

Code: Select all

INSERT INTO modules_company //This is where I am stuck

Can anyone tell me how I would do this.

I looked at

Code: Select all

<?php
foreach ( $_POST as $key => $val ) 
{$key}: {$val}
  ?>
Which lists all the checked modules but I don't know where to go from here.

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

echo '<li><input name="foo[]" type="checkbox" id="'.$module_name.'" value="'.$module_name.'" />&nbsp;&nbsp;<strong>'.$module_name.'</strong></li>';
$_POST['foo'] will be an array of module names.
Post Reply