Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-18-2012, 03:17 PM   PM User | #1
Sayfuddin
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Sayfuddin is an unknown quantity at this point
SMS functionality to PHP website

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.com/index.php?owpn=422). I will use Mysql database to puit 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:

Code:
<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>
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.

Code:
<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>
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
Sayfuddin is offline   Reply With Quote
Old 10-18-2012, 03:35 PM   PM User | #2
alemcherry
New Coder

 
Join Date: Apr 2010
Posts: 55
Thanks: 0
Thanked 4 Times in 4 Posts
alemcherry is an unknown quantity at this point
Insert and Select are basic operations in MySQL and there is no more simple solution. Just make sure that whatever you are reading from database is deleted to avaoid it getting read again.

I am not aware of the gateway you mentioned or its API. Common sense says that the gateway would need your MySQL server, user, pass, database name to read it from your server. However, with most shared hosts, remote MySQL connection are not allowed. So check with your host before proceeding. An HTTP based API would be safer option.
__________________
Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon
alemcherry is offline   Reply With Quote
Old 10-18-2012, 06:51 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by alemcherry View Post
Insert and Select are basic operations in MySQL and there is no more simple solution. Just make sure that whatever you are reading from database is deleted to avaoid it getting read again.

I am not aware of the gateway you mentioned or its API.
You are now! It's a spammer just like the other thread - also mentioning http://ozekisms.com/. It's someone dressing up an advert as a request for help in both threads.

Quote:
Originally Posted by alemcherry View Post
Common sense says that the gateway would need your MySQL server, user, pass, database name to read it from your server.
No, all the gateway needs is a url to a script on your server / account where you can handle the response / insert it into a DB. Why would you think they need direct access to the database themselves?
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Tags
gateway, mysql, php, sms

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:16 PM.


Advertisement
Log in to turn off these ads.