Jump to content

Recommended Posts

If i check more than one checkbox. I dont get any value from database.

 

HTML

<form method="post">
    <input type="checkbox" name="receiver[]" value="cheater">CHEATER
    <input type="checkbox" name="receiver[]" value="un-verified">UN-VERIFIED
    <input type="checkbox" name="receiver[]" value="inactive">INACTIVE
    <input type="checkbox" name="receiver[]" value="active">ACTIVE
    <input type="submit" name="submit" value="ADD">
</form>

PHP

$errors = array();
$success = NULL;
$error = NULL;
$var['receiver'] = isset($_POST['receiver']) ? $_POST['receiver'] : NULL;
.................

if(!empty($_POST['submit'])){
    // FORM VALIDATION //
}

if(!empty($_POST['submit']) and empty($errors)){
	
    $status = array_map('strval', $var['receiver']) + array(0);
    $statusSql = implode(',', $status);
	
    $query = 'SELECT email FROM users WHERE status IN("'.$statusSql.'")';
    $select = $db->prepare($query);
    $select->execute();
	
    $arrayData = array();
    while($row = $select->fetch(PDO::FETCH_ASSOC)){
        $arrayData[] = $row['email'];
    }
	
    $errors[] = implode(',', $arrayData);
	
}

require_once 'includes/antiCsrf/index.php';
$csrf = new antiCsrf();

$smarty->assign('success', $success);
$smarty->assign('error', $error);
$smarty->assign('errors', $errors);
$smarty->assign('csrfKey', $csrf->csrfKey());
$smarty->assign('csrfToken', $csrf->csrfToken());
$smarty->assign('var', $var);
.................
Link to comment
https://forums.phpfreaks.com/topic/294105-select-email-from-users-where-status-in/
Share on other sites

i recommend that you echo the $query value so that you can see if it is what you expect.

 

also, why are you putting external data values into the sql query statement, then preparing the query? you use a prepared query by putting place-holders into the sql query statement where the data values are at, then you bind the actual data to the place-holders.

What does $status look like after you do this:

$status = array_map('strval', $var['receiver']) + array(0);

I'm not sure what that array(0) is supposed to do. Shouldn't those be square brackets and why are you adding that anyway?

 

Besides that, it doesn't look like your database is normalized for your statuses. It seems those should be IDs instead of their names.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.