i am trying to integrate the sms gateway and its working fine when i sent it through the normal form but it is creating a little bit problem while sending it through checkbox.usually, i have around 50 data on the page including checkbox with each data.Whenever i am sending message through checkbox, it is sending blank message on phone but the data is stored in database.

Here is my whole code :

<?php 
include("config.php");

if(isset($_POST['save'])){

  $user = "***********";
  $password = "********";
  $senderid = "*************";
  $contact_sms = $_POST['contact_sms'];
  $checkbox = $_POST['check'];
  $contact_sms = $_POST['contact_sms'];
  for($i=0;$i<count($checkbox);$i++){

  $bulksms="INSERT INTO bulk_sms (sent_sms,contact_sms) VALUES('".$checkbox[$i]. "','$contact_sms')";
  $smsquery=mysqli_query($conn, $bulksms);
}
}

$numsql="SELECT * FROM inventory_details where status ='0'";
$querytot=mysqli_query($conn, $numsql);
$total=mysqli_num_rows($querytot);

$sql="SELECT * FROM inventory_details where status ='0' AND role='0' limit 0,100";  
if(isset($_REQUEST['search'])){
    $search_item =mysqli_real_escape_string($_REQUEST['search_box']);
    $sql .= " WHERE catagory_name='{$search_item}'";
    }  
$query=mysqli_query($conn, $sql);

$smsurl = "http://kit19.com/ComposeSMS.aspx?";

function httpRequest($url){
    $pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
    preg_match($pattern,$url,$args);
    $in = "";
    $fp = fsockopen($args[1],80, $errno, $errstr, 30);
    if (!$fp) {
       return("$errstr ($errno)");
    } else {
        $args[3] = "C".$args[3];
        $out = "GET /$args[3] HTTP/1.1\r\n";
        $out .= "Host: $args[1]:$args[2]\r\n";
        $out .= "User-agent: JUST YELLOW PAGE\r\n";
        $out .= "Accept: */*\r\n";
        $out .= "Connection: Close\r\n\r\n";

        fwrite($fp, $out);
        while (!feof($fp)) {
           $in.=fgets($fp, 128);
        }
    }
    fclose($fp);
    return($in);
}

function SMSSend($phone, $msg, $debug=false){
      global $user,$password,$senderid,$smsurl;

      $url = 'username='.$user;
      $url.= '&password='.$password;
      $url.= '&sender='.$senderid;
      $url.= '&to='.urlencode($phone);
      $url.= '&message='.urlencode($msg);
      $url.= '&priority=1';
      $url.= '&dnd=1';
      $url.= '&unicode=0';


      $urltouse =  $smsurl.$url;
      if ($debug) { echo ""; }

      //Open the URL to send the message
      $response = httpRequest($urltouse);
      if ($debug) {
        //   echo "Response: <br><pre>".
        str_replace(array("<",">"),array("&lt;","&gt;"),$response).
           "</pre><br>"; }

      return($response);
}

$contact_sms = $_POST['contact_sms'];
$checkbox = $_POST['check'];
$debug = true;

SMSSend($contact_sms,$checkbox,$debug);

?>

<div class="container search" >
  <form action="searchbox-bulksms.php">
    <div class="row">
      <div class="col-md-6 col-sm-6" >
        <input type="text" class="form-control" name="search_box" placeholder="SEARCH BY FIRM NAME , CATEGORY NAME  AND MOBILE NO">
      </div>
      <div class="col-md-4 col-sm-4">
        <a href="index.php?activity=bulksms"><button class=" btn btn-primary" name="search"><span class="fa fa-search"> </span> Filter</button></a>
      </div>
    </div>
  </form>   
</div>

<div class="container cate_head">
  <div class="row">
    <div class="col-md-12 tot_ivnt">
      <strong><span class="fa fa-building-o"></span> TOTAL NUMBER OF INVENTORY : <?php echo $total ;?></strong>
    </div>
  </div>

  <div class="row invent_det">
  <div class="col-md-1 "><strong>ID</strong></div>
  <div class="col-md-3 "><strong>NAME</strong></div>
  <div class="col-md-1 "><strong>POSITION</strong> </div>
  <div class="col-md-2 "><strong>CITY</strong></div>
  <div class="col-md-2 "><strong>CATEGORY</strong></div>
  <div class="col-md-2 "><strong>PRIMARY MOBILE NO.</strong></div>
  <div class="col-md-1 "><strong><input type="checkbox" id="checkAl"> Select </strong></div>
  </div>
</div>
<form method="post" action="">
<div class="container">
  <?php
$i=0;
$today_date=date("Y-m-d H:i:s", time()); 
    while($row=mysqli_fetch_assoc($query)){
    $id = $row['id'];
    $inventorybackground = $row['inventorybackground'];
    $inventorycolor = $row['inventorycolor'];
    $firm_name = $row['firm_name'];
    $position = $row['position'];
    $city = $row['city'];
    $catagory_name = $row['catagory_name'];
    $PrimaryMobile_no = $row['PrimaryMobile_no'];
  ?>

    <div class="row" style="background-color: <?php echo $inventorybackground; ?> !important; color: <?php echo $inventorycolor; ?>; padding-top: 10px;">
        <div class="col-md-1 inventory-data">
          <input type="text" class="form-control" name="id_sms" value="<?php echo $id;?>" disabled>
        </div>

        <div class="col-md-3 inventory-data">
          <input type="text" class="form-control" name="check[0]" value="<?php echo $firm_name;?>" disabled>
        </div>

        <div class="col-md-1 inventory-data">
          <input type="text" class="form-control" name="check[1]" value="<?php echo $position;?>" disabled>
        </div>

        <div class="col-md-2 inventory-data">
          <input type="text" class="form-control" name="check[2]" value="<?php echo $city;?>" disabled>
        </div>

        <div class="col-md-2 inventory-data">
          <input type="text" class="form-control" name="check[3]" value="<?php echo $catagory_name;?>" disabled>
        </div>

        <div class="col-md-2 inventory-data">
          <input type="text" class="form-control" name="check[4]" value="<?php echo $PrimaryMobile_no;?>" disabled>
        </div>

        <div class="col-md-1 inventory-data"><input type="checkbox" id="checkItem" name="check[]" value="<?php echo $row["firm_name"]; ?>-<?php echo $row["PrimaryMobile_no"]; ?>"></div>
    </div>

<?php
$i++;
}
?>

</div>
        <div class="inventory-data">
          <input type="text" class="form-control" name="contact_sms" placeholder="Contact Number..">
        </div>
<p align="center"><button type="submit" class="btn btn-success" name="save" style="margin-bottom: 150px;">Move All</button></p>
</form>
<script>
$("#checkAl").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
</script>

Whenever i am sending message using above code, it stores data in my database but on phone it is sending blank message. But when i replace $checkbox = $_POST['check']; with a static value like $checkbox = "testing"; it sent sms 'testing' on the phone. I think, the problem in storing value near $checkbox = $_POST['check'];. Please help me out, i am stuck here !. Thanks in advance ;

0 Answers