0

I'm trying to get a simple drop down selection form to alter the reg_id query to send gcm messages. The query is selected reg_id from all that channel!='0' but not the "AND .$and. extra condition. Seems simple enough but not working correctly. The echo of $count is always the same

<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;
}

?>
Robert Goodrick
  • 190
  • 1
  • 11

1 Answers1

4

form method is POST, but your checking for $_GET (ie $_GET['cat'])