sms checkbox php issue

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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: sms checkbox php issue

Post by Celauran »

Code: Select all

echo '<label><input class="checkbox" type="checkbox" value="'.$row['customer_phone'].'" name="customer_phone[]" id="customer_phone"/> '.$row['customer_name'].'&nbsp;-&nbsp;'.$row['customer_phone'].'</label>';
...
$customer_phone = $db->real_escape_string($_POST['customer_phone']);
$smsmessage = $db->real_escape_string($_POST['smsmessage']);

// Example of use
$response = sendSMS('username', 'password', $customer_phone, $smsmessage, $from);
Your form specifies customer_phone[] as an array but your form processing ignores that fact. You need to iterate over the $_POST['customer_phone'] array and send the message to each one individually.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: sms checkbox php issue

Post by Celauran »

Stay far, far away from eval. Your existing code only needs a small tweak:

Code: Select all

$smsmessage = $db->real_escape_string($_POST['smsmessage']);

foreach ($_POST['customer_phone'] as $phone) {
    $response = sendSMS('username', 'password', $phone, $smsmessage, $from);
}
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: sms checkbox php issue

Post by Celauran »

Post Reply