Updating Mysql with checked boxes from Registration

Security issues related to php and mysql usage. How to make your code secure? Security measures and configurations? It's all in here!

Moderators: egami, macek, gesf

Post Reply
rbrown1983
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Aug 22, 2020 11:11 am

Sat Aug 22, 2020 11:15 am

I have a registration form i am trying to work on as part of a project and in my code i want to know which checkboxes have been selected and which havent. SO far the below code will enter in to a varchar DB the entry "on" if the checkbox is checked but nothing else, so i am not sure how to make sense of that, i.e. would it not be off, off, on, on if you only were to select the last 2 checkboxes for example. here is some of my code only the relevant bit for checking each box, adding to SQL and the html checkbox itself..

Code: Select all

<?PHP
$Industrybtn = '';
                   if(!empty($_POST["Industry"]))
                   {
                       foreach($_POST["Industry"] as $Industry)
                       {
                           $Industrybtn .= $Industry . ', ';
                       }
                   }
      
                 $stmt = mysqli_prepare($con, "INSERT INTO inf VALUES (?, ?, ?, ?, ?, ?)");
                 mysqli_stmt_bind_param($stmt, "ssssss", $int, $inf_fname, $inf_lname, $inf_email, $inf_password, $Industrybtn);
                 mysqli_stmt_execute($stmt);
                  ?>

<div class="checkboxes">
                    <input type="checkbox" name="Industry[]" id="checkbox_id" style="margin-bottom:15px"><label for="checkbox_id">Dinning</label>
                    <input type="checkbox" name="Industry[]" id="checkbox_id1" style="margin-bottom:15px"><label for="checkbox_id1">Jewellery</label>
                    <input type="checkbox" name="Industry[]" id="checkbox_id2" style="margin-bottom:15px"><label for="checkbox_id2">Clothing</label>                 
                    </div><br>


User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1191
Joined: Mon Feb 22, 2016 5:52 pm

Sat Aug 22, 2020 2:22 pm

You will only get selected boxes returned.

Have a look here for more information.
rbrown1983
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Aug 22, 2020 11:11 am

Sun Aug 23, 2020 9:43 am

Thanks, so how do I know which box was selected? There doesn’t seem to be any logic to the order so how will we know what they selected?
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1191
Joined: Mon Feb 22, 2016 5:52 pm

Mon Aug 24, 2020 7:14 am

so how do I know which box was selected?
If you only want one selection, use a radio control.
There doesn’t seem to be any logic to the order so how will we know what they selected?
You're the one writing the logic.


Have you read the link?
Post Reply