Support Forums

Full Version: multiple check boxs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i need multiple check boxs from a list of "courses" i have in a mysql database i cant figure this out
Provide the source where you're expiriencing the problem.
Or do you want an example?
more of an example

like kinda what im looking for

is

check boxes each one a differnt class wich is in a database (i have the courses in the database)
user registers taken to this page(have that) and
the selected all the courses there in and hit submit it will sign there user_id to the class_id if that makes sense?
Not knowing your database structure it'd be hard to give accurate queries but this is what I'd do:

PHP Code:
<?php
echo "<form method=\"post\" action=\"\">\n";
$query mysqli_query($link"SELECT * FROM `courses`;");
while(
$course mysqli_fetch_assoc($query))
{
    echo 
"<input type=\"checkbox\" name=\"courses[]\" id=\"{$course['name']}\" value=\"{$course['id']}\"> <label for=\"{$course['name']}\">{$course['name']}</label>\n";
}
echo 
"</form>\n";
if(
$_POST['courses'])
{
    
$list_of_courses "";
    foreach(
$_POST['courses'] as $course)
    {
        
$course htmlspecialchars($course);
        
$list_of_courses[] = $course;
    }
    
$new_list_of_courses implode("|"$list_of_courses);
    
$update mysqli_query($link"UPDATE `users` SET `courses` = '{$new_list_of_courses}' WHERE `user` = '{$whatever}';");
}
?>

Then you'd get something like 1|2|4|8|16 as a list of courses associated to each use, that's how I'd arrange it.