SQL query help with submit

Hello,
I’m confused I couldn’t get out of it

There are 2 checkboxes
<input type="checkbox" name="group[]" value="1"> <input type="checkbox" name="group[]" value="2">

There is 1 input text
<input type="text" name="emails" />

My sample code

// If checkbox is selected but input is empty

$usergroups = implode(",", $_POST['group']);

if($_POST['group']){

$users = $mysqli->query("SELECT * FROM users WHERE group IN (".$usergroups.")");

}
// If input mail is entered, checkboxes will be ignored
// <input type="text" name="emails" value="[email protected], [email protected], [email protected]" /> 
$emails = explode(",", $_POST['emails']);

if($_POST['gorup']){

$users = $mysqli->query("SELECT * FROM users WHERE email IN (".$emails.")");

}

while ($row = $users->fetch_assoc()) {

}

So what now? You may at least tell us what problems you encounter, what source you expect to be the problem, and what you did to try to fix it yourself.

I can’t explain in detail because I don’t speak English
I’m trying to explain briefly
No problem sending
group IDs are running but mailer does not work
I’m a rookie, do you see errors in the code?

the group[] array with checkboxes is a bad combination. You can use array’s with checkboxes but you should use array keys. For example:

<input type="checkbox" name="group[1]"> 
<input type="checkbox" name="group[2]"> 

Values are less important because a checkbox can just be ON or OFF. The important thing to know is that checkboxes only exists in the $_POST array if the checkbox is checked.

That is why you must test if the checkbox is checked with the function isset().

if(isset($_POST['group'][1])) {
    // checkbox 1 is checked
}
if(isset($_POST['group'][2])) {
    // checkbox 2 is checked
}

Or in a loop (common with array’s

for($i = 1 ; $i <= count($_POST['group']) ; $i++) {
    if(isset($_POST['group'][$i])) {
       echo 'Checkbox ' . $i . ' is checked.';
    }
}

You may want to check your typo.

But also you will get a specific SQL error if you ask for it:

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

But someone might even just delete your database:

How can I delete a database?
Can you tell me more plainly?

I created an array this way
Array
(
[0] => 1
[1] => 2
)

How do I array input text emails?

I’ve solved the problem for now
Thank you all

Sponsor our Newsletter | Privacy Policy | Terms of Service