Ok i am tryna make this code excute for every phone number in my db. Before following advice here i was only able to send to one number at a time, i got advice to add a while statment to loop it. However my code don't wanna work no more. Here is before and after. I know i did something wrong.
BEFORE (Working-no db)
// Set SMS options
$data['post'] = array (
'_rnr_se' => $rnrse,
'phoneNumber' => '123456789',
'text' => 'This is a test SMS',
'id' => ''
);
// Send the SMS
$response = xcurl::fetch('api.gateway.com/', $data);
// Evaluate the response
$value = json_decode($response['data']);
if($value->ok) {
echo "SMS message sent! ({$data['post']['phoneNumber']}: {$data['post']['text']})";
} else {
echo "Unable to send SMS! Error Code ({$value->data->code})
";
echo 'data: '; print_r( $data); echo "
";
echo 'response: '; print_r($response);
}
AFTER(Not working with db)
// Set SMS options
mysql_connect("localhost", "music", "") or
die("Could not connect: " . mysql_error()); mysql_select_db("music");
$result = mysql_query("SELECT id, numbers FROM account_templates");
while ($row = mysql_fetch_array($result)) {
$data['post'] = array (
'_rnr_se' => $rnrse,
'phoneNumber' => $row['numbers'],
'text' => 'This is a test SMS',
'id' => ''
);
// Send the SMS
$response = xcurl::fetch('api.gateway.com', $data);
// Evaluate the response
$value = json_decode($response['data']);
}
if($value->ok) {
echo "SMS message sent! ({$data['post']['phoneNumber']}: {$data['post']['text']})";
} else {
echo "Unable to send SMS! Error Code ({$value->data->code})
";
echo 'data: '; print_r( $data); echo "
";
echo 'response: '; print_r($response);
}
The way it is now, the sending process is running through the while loop, but the process of checking whether the SMS was sent is not.
It could be as simple as changing the position of a }
.
Take away this bracket:
// Evaluate the response
$value = json_decode($response['data']);
} <------------------------------------------------ remove that one
and move it
echo 'response: '; print_r($response);
}
} <------------------------------------------------add here