Results 1 to 3 of 3

Thread: php sms api mysql issue

  1. #1
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default php sms api mysql issue

    Hi

    I am using text marketer sms api script and been testing the following script and found it is not working, the scripts are not producing any errors but the sms texts are not being sent, can someone please take a look at the scripts and see where I gone wrong as I can't work it out

    Below is my send-sms-message.php script
    PHP Code:
    <?php

    ini_set
    ('display_startup_errors',1);
    ini_set('display_errors',1);
    error_reporting(-1);

    $db mysqli_connect("localhost" """") or die("Check connection parameters!"); 
    // Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)  
    mysqli_select_db($db,"") or die(mysqli_error($db));

    if (
    mysqli_connect_error()) {
        die (
    'Failed to connect to MySQL');
    }

    $sqlCommand "SELECT id, customer_name, customer_phone FROM repairs";

    $query mysqli_query($db$sqlCommand) or die (mysqli_error($db));

    echo 
    '<form action="send-sms.php" method="post">';
    echo 
    '<select>';
    echo 
    '<option value="">Choose the mobile number</option>';
    while(
    $rowmysqli_fetch_assoc($query)){
    echo 
    '<option value="'.$row['customer_name'].$row['customer_phone'].'">'.$row['customer_name'].'&nbsp;-&nbsp;'.$row['customer_phone'].'</option>';
    }
    echo 
    '</select>';

    echo 
    '<input type="submit" value="Send SMS">';
    echo 
    '</form>';

    ?>
    Below is my send-sms.php script

    PHP Code:
    <?php

    ini_set
    ('display_startup_errors',1);
    ini_set('display_errors',1);
    error_reporting(-1);

    function 
    sendSMS($username$password$mobnumber$message$originator) {
        
    $URL 'http://api.textmarketer.co.uk/gateway/'."?username=$username&password=$password&option=xml";
        
    $URL .= "&to=$mobnumber&message=".urlencode($message).'&orig='.urlencode($originator);
        
    $fp fopen($URL'r');
        return 
    fread($fp1024);
    }

    $db mysqli_connect("localhost" """") or die("Check connection parameters!"); 
    // Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)  
    mysqli_select_db($db,"") or die(mysqli_error($db));

    if (
    mysqli_connect_error()) {
        die (
    'Failed to connect to MySQL');
    }

    $sqlCommand "SELECT id, customer_name, customer_phone FROM repairs";

    $query mysqli_query($db$sqlCommand) or die (mysqli_error($db));

    //fetch the data from the database 
    while ($row mysqli_fetch_array($query)) {

    $mobnumber $row['customer_phone'];
    $country_code '44';

    $mobnumber str_replace(' '''$row['customer_phone']);
    $mobnumber substr_replace($mobnumber''.$country_code0, ($mobnumber[0] == '0'));

    //var_dump($mobnumber);

    }

    $message "Name:".$row['customer_name'] . '&nbsp;' 'Your PC/Laptop is ready for collection';
        
        
    // Example of use
    $response sendSMS('DJkGc7''97q84F'$mobnumber"Your PC/Laptop is ready for collection"'ITDoneRight');
            
    var_dump($response);
    ?>
    If I hard code the mobile number in as per the script below, the SMS works and comes through but need it to send the SMS to the mobile number I select from the select menu on the send-sms-message.php page

    PHP Code:
    $response sendSMS('DJkGc7''97q84F''447538503276'"Your PC/Laptop is ready for collection"'ITDoneRight'); 
    Can anyone help me please as am really stuck with it

  2. #2
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    UPDATE:

    Hi, sorry got a update, it seems to be working now but I think it is looping cause of the while code in the send-sms-message.php and send-sms.php scripts and sending to all numbers and not just the one I choose within the select menu, is it possible just to check the code please

    below is the send-sms-message.php script

    Code:
    <?php
    
    $db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!"); 
    // Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)  
    mysqli_select_db($db,"") or die(mysqli_error($db));
    
    if (mysqli_connect_error()) {
        die ('Failed to connect to MySQL');
    }
    
    $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs";
    
    $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
    
    echo '<form action="send-sms.php" method="post">';
    echo '<select name="customer_phone">';
    echo '<option value="">Choose the mobile number</option>';
    while($row= mysqli_fetch_assoc($query)){
    
    echo '<option value="'.$row['customer_phone'].'">'.$row['customer_name'].'&nbsp;-&nbsp;'.$row['customer_phone'].'</option>';
    
    }
    echo '</select>';
    
    echo '<input type="submit" value="Send SMS">';
    echo '</form>';
    
    ?>
    below is the send-sms.php script

    Code:
    <?php
    
    ini_set('display_startup_errors',1);
    ini_set('display_errors',1);
    error_reporting(-1);
    
    function sendSMS($username, $password, $customer_phone, $message, $originator) {
        $URL = 'http://api.textmarketer.co.uk/gateway/'."?username=$username&password=$password&option=xml";
        $URL .= "&to=$customer_phone&message=".urlencode($message).'&orig='.urlencode($originator);
        $fp = fopen($URL, 'r');
        
    return fread($fp, 1024);
    }
    
    $db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!"); 
    // Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)  
    mysqli_select_db($db,"") or die(mysqli_error($db));
    
    if (mysqli_connect_error()) {
        die ('Failed to connect to MySQL');
    }
    
    $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs";
    
    $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
    
    //fetch the data from the database 
    while ($row = mysqli_fetch_array($query)) {
    
    $customer_phone = $row['customer_phone'];
    
    if (isset($_POST["submit"])) {
    
    //var_dump($customer_phone);
    
    }
        
        // Example of use
    $response = sendSMS('DJkGc7', '97q84F', $customer_phone, 'Your PC/Laptop is ready for collection', 'ITDoneRight');
    //var_dump($response);
    }
    ?>

  3. #3
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Hi

    I have got it sort of working but the previous script was looping through all the records instead of a specific one so now I altered my send-sms-message.php script to the following but with that I got a undefined index: id error

    Code:
    <?php
    
    $db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!"); 
    // Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)  
    mysqli_select_db($db,"") or die(mysqli_error($db));
    
    if (mysqli_connect_error()) {
        die ('Failed to connect to MySQL');
    }
    
    $smsid = $db->real_escape_string($_GET['id']);
    
    $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs WHERE id = '$smsid'";
    
    $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
    
    echo '<form method="get" action="send-sms.php">';
    echo '<select>';
    echo '<option value="">Choose the mobile number</option>';
    while($row= mysqli_fetch_assoc($query)){
    
    echo '<option name="id" value="'.$row['id'].'">'.$row['customer_name'].'&nbsp;-&nbsp;'.$row['customer_phone'].'</option>';
    
    }
    echo '</select>';
    
    echo '<input type="submit" value="Send SMS">';
    echo '</form>';
    
    ?>

Similar Threads

  1. php form mysql issue
    By ianhaney in forum PHP
    Replies: 2
    Last Post: 07-03-2015, 04:16 AM
  2. mySQL Single Quote Issue
    By jdadwilson in forum MySQL and other databases
    Replies: 1
    Last Post: 07-24-2013, 01:11 AM
  3. PHP URL MySQL Issue
    By DigiplayStudios in forum PHP
    Replies: 4
    Last Post: 09-25-2010, 03:46 PM
  4. mysql and url issue
    By viktor in forum PHP
    Replies: 0
    Last Post: 02-16-2010, 02:49 AM
  5. Array issue with MySQL. I'm about to die
    By janniesekind in forum PHP
    Replies: 0
    Last Post: 02-04-2009, 11:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •