使用复选框发送时发送空白消息

时间:2019-04-29 11:15:28

标签: php mysql sms-gateway

当我通过正常形式发送它时,我正在尝试整合sms网关及其工作正常,但是在通过checkbox发送它时会产生一些问题。通常,我在页面上有大约50个数据,其中包括带有每个数据。只要我通过复选框发送消息,它就会在电话上发送空白消息,但数据存储在数据库中。

这是我的完整代码:

<?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>

每当我使用以上代码发送消息时,它将数据存储在我的数据库中,但在电话上它发送空白消息。 但是,当我用$checkbox = $_POST['check'];之类的静态值替换$checkbox = "testing";时,它在手机上发送了短信“测试”。 我认为,在$checkbox = $_POST['check'];附近存储值的问题。 请帮帮我,我被困在这里!。 预先感谢;

0 个答案:

没有答案