我正在尝试使用简单的下拉选择表单来更改reg_id查询以发送gcm消息。查询从所有通道中选择reg_id!='0'但不是“AND。$和。额外条件。看起来很简单但不能正常工作。$ count的回显始终是相同的
<html>
<head>
<title>Notifications</title>
</head>
<body>
<form method="post">
<textarea type="text" name="msg" id="msg" rows="25" cols="80"></textarea>
<input type="submit" value="send"/>
<div class="col-md-2">
<select name="cat" class="form-control">
<option value="All">All</option>
<option value="ranked">ranked</option>
<option value="new">new</option>
</select>
</div>
</form>
</body>
</html>
<?php
switch($_GET['cat']){
case 'All':
$and='user_id!="2095"';
break;
case 'ranked':
$and='salutes>"10"';
break;
case 'new':
$and='created=CURDATE()';
break;
default:
$and='user_id!="2095"';
}
if(isset($_POST['msg'])){
$pdo=new PDO('mysql://hostname=localhost;dbname=database', 'user', 'password');
$user_ids=$pdo->query('select reg_id from accounts where channel!="0" AND '.$and.' AND user_id!="2095"');
$user_ids=$user_ids->fetchAll(PDO::FETCH_ASSOC);
$ids=array();
foreach($user_ids as $row){
$ids[]=$row['reg_id'];
$count++;
}
// API access key from Google API's Console
define( 'API_ACCESS_KEY',"***************");
$msg = array
(
'privateMessage' => "{$_POST['msg']}",
'messageText' => "{$_POST['msg']}",
'user_id' => "2095",
'handle' => "Administration",
'rank' => "z"
);
$fields = array
(
'registration_ids' => $ids,
'data' => $msg,
"time_to_live" => 3,
"priority" => "high",
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $count;
}
?>
答案 0 :(得分:4)
form方法是POST,但是你检查$ _GET(即$_GET['cat']
)