如果第一次尝试在PHP中成功,如何防止第二次发送文本消息?
我在数据库中有一些记录,如果一个特定id的计数超过4,那么我想向那个特定的现场电话发送短信。但是如果第一次尝试发送成功,我不想再向该特定号码发送任何后续消息 我试过使用:如果第一次尝试在PHP中成功,如何防止第二次发送文本消息?,php,mysql,sms,Php,Mysql,Sms,我在数据库中有一些记录,如果一个特定id的计数超过4,那么我想向那个特定的现场电话发送短信。但是如果第一次尝试发送成功,我不想再向该特定号码发送任何后续消息 我试过使用: if( file_exist($url) ) { die( 'already sent' ); } file_put_content( $url, 1 ); // A lot of code unlink( $url ); 但它不起作用 $reminderQuery = "SELECT count(*) FR
if( file_exist($url) ) {
die( 'already sent' );
}
file_put_content( $url, 1 );
// A lot of code
unlink( $url );
但它不起作用
$reminderQuery = "SELECT count(*) FROM acceptance WHERE clientID = '$clientID' ";
$reminderresult = $pdo->prepare($reminderQuery);
$reminderresult->execute();
$number_of_rows = $reminderresult->fetchColumn();
if($number_of_rows > 4){
$remindersms= "SELECT * FROM clients WHERE id = '$clientID' ";
$remindersendsms = $pdo->prepare($remindersms);
$remindersendsms->execute();
while ($remindersmsnoti = $remindersendsms->fetch()){
$phoneNos = $remindersmsnoti['phone'];
$key = "*******************"; // Remember to put your own API Key here
$phoneNo = $phoneNos;
$message = "*******************";
$sender_id = "YENKOR"; //11 Characters maximum
//encode the message
$msg = urlencode($message);
//prepare your url
$url = "*********************";
$response = file_get_contents($url) ;
}
}
我想上面的代码不发送任何消息后,短信已经发送了
您能告诉我正确的方法吗?为什么不在最初设置为0的客户表中添加一列
sms\u sent
(不过,对于那些在接受表中已经有4条或更多记录的客户,您可能希望将其设置为1,前提是已经为他们发送了sms消息)。然后将初始SQL更改为:
select * from clients c join (
select clientId from acceptance having count(*) >= 4
) a on c.id = a.clientId and not c.sms_sent
这将选择所有在受理
表上有4条或4条以上记录且尚未发送sms消息的客户机(如果您只需要一个特定的客户机,如示例所示,您可以添加附加条件)。然后,当您成功发送sms消息时,您将客户机
表中客户机的sms_sent
列更新为1
作为旁注,由于您已经在使用一条准备好的语句,因此应该这样做以避免SQL注入攻击:
$reminderQuery = "SELECT count(*) FROM acceptance WHERE clientID = ?";
$reminderresult = $pdo->prepare($reminderQuery);
$reminderresult->execute(array($clientId());
上面假设$clientId是一个字符串。如果没有,则必须使用
bindValue
(您需要将$clientID
作为参数传递。是一个从会话中获取的变量,但不是现在的一部分。因为我想缩短代码,为什么要缩短代码?这样做可能会破坏您自己的代码。@kateorlova请不要在建议的编辑中将标记添加到标题中。有专门的空间用于标记s