1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

SMS from Mysql through PHP website

Discussion in 'Databases' started by Sayfuddin, Oct 18, 2012.

  1. #1
    Hi! I want to create a PHP site with added SMS functionality (dating services site). I was suggested a gateway to use as the engine (google: ozekisms php). I will use Mysql database to put the records in it.

    As the documentation mentions PHP website can send SMS messages by simply placing records into a mysql database table called ozekimessageout. So I can create HTML form, that the visitors of the website will fill in. When the form is submitted I am able to create record in the ozekimessagout database table using an SQL INSERT statement. See example:

    <HTML>
    <BODY>
     
    <H1> Send an SMS </H1>
     
    <?php
    $phonenum = $_GET['phonenum'];
    $messagetext = $_GET['messagetext'];
     
    if ($phonenum<>'') {
     
      $conn = mysql_connect("localhost", 'ozeki', 'abc123');
      if (!$conn) {
        die('Could not connect to database ' . mysql_error());
      }
     
      mysql_select_db('ozekisms');
      $sql = "INSERT INTO ozekimessageout (receiver,msg,status) ".
             "VALUES ('$phonenum','$messagetext','send')";
      mysql_query($sql);
      mysql_close($conn);
     
      echo "The message has been submitted for sending <br><br>";
    }
    ?>
     
    <FORM action=send.php METHOD=GET>
      Mobil phone number:
      <INPUT TYPE="TEXT" SIZE="16" NAME="phonenum" VALUE="+44777888999">
      <br>
      <TEXTAREA NAME="messagetext" ROWS=5 COLS=40>Hello world</TEXTAREA>
      <br>
      <INPUT TYPE=SUBMIT VALUE=SEND>
    </FORM>
     
    </BODY>
    </HTML>
    Code (markup):
    To receive SMS messages all Ihave to do is select the records from the ozekimessagin database table. This can be done by issuing a simple SQL SELECT statement.


    
    <HTML>
    <BODY>
     
    <H1>List incoming messages</H1>
     
    <?php
      $conn = mysql_connect("localhost", 'ozeki', 'abc123');
      mysql_select_db('ozekisms');
      $sql = "SELECT sender,senttime,msg FROM ozekimessagein ORDER BY senttime desc";
      $res = mysql_query($sql);
      $cn = mysql_num_rows($res);
     
      for ($x=0;$x<$cn;$x++) {
         list ($sender,$senttime,$msg) = mysql_fetch_row($res);
         echo "<li>$senttime, <b>$sender</b>, $msg";
      }
     
      mysql_close($conn);
    ?>
     
    </BODY>
    </HTML> 
    Code (markup):
    Maybe you can get some useful idea from this description and if you have better solutions to insert or select records into Mysql database, please share with me.


    TX
    Boris

    SEMrush
     
    Sayfuddin, Oct 18, 2012 IP
    SEMrush
  2. jadexe

    jadexe Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #2
    Hello,
    Your script is sql injection vulnerable. You should add the following lines
    
    $phonenum = mysql_real_escape_string($phonenum);
    $messagetext = mysql_real_escape_string($messagetext);
    
    PHP:
    before this line:
    
    $sql = "INSERT INTO ozekimessageout (receiver,msg,status) ".          "VALUES ('$phonenum','$messagetext','send')";
    
    PHP:
    Instead of doing the for loop I'd use this:
    while ($row = mysql_fetch_array($res)){
         echo "$row['senttime'], <b>$row['sender']</b>, $row['msg']";
    }
    
    PHP:
     
    jadexe, Oct 26, 2012 IP
  3. aimanjavaid

    aimanjavaid Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    I am using Ozeki SMS Server. Can i apply this using Ozeki sms server , php n mysql?
     
    aimanjavaid, Aug 2, 2014 IP
  4. aimanjavaid

    aimanjavaid Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    I want to select more than one phone number from mysql database and then i want to sent the sms to all contact numbers selected from the database. Can anyone help me please?
     
    aimanjavaid, Aug 2, 2014 IP