|
 |
|
รบกวนช่วยแทรกโค้ดเหล่านี้ให้ส่งSMS แล้วลงไปในฐานข้อมูล MySQL ให้ได้ทีครับ ขอร้องนะครับ ช่วยหน่อยน้า |
|
 |
|
|
 |
 |
|
คือผมทำหน้าเว็บโดยใช้ PHP เชื่อมต่อฐานข้อมูล Mysql อยู่ครับ แล้วผมต้องการสร้างหน้าเว็บPHPในการส่ง SMS ผ่านฟอร์ม
โดยผมได้ใช้โปรแกรม Ozeki Server เพื่อเป็นตัวกลางในการส่งSMS ที่ได้เชื่อมต่อกับโทรศัพท์มือถือของผม ซึ่งเปรียบเสมือนเบอร์โทรผมเป็นผู้ส่งไปยังผู้รับSMS อะครับ
โดย sendsms_form.html จะเป็นหน้าฟอร์มสำหรับรับค่าที่ได้กรอกลงไป แล้วนำค่านั้นส่งไปยัง sendsms.php เพื่อส่ง SMS ต่อไป
โค้ดส่งSMS สองตัวแรกแล้วทำการส่งSMS ซึ่งไม่ได้เชื่อมต่อกับฐานข้อมูลแต่อย่างใด
sendsms_form.html
<html>
<form method=post action='sendsms.php'>
<table border=0>
<tr>
<td>Sender</td><td><input type='text' name='sender'></td>
</tr>
<tr>
<td>Recepient</td><td><input type='text' name='recepient'></td>
</tr>
<tr>
<td>Message</td><td><input type='text' name='message'</td>
</tr>
<tr>
<td colspan=2><input type=submit name=submit value=Send>
</form>
</tr>
</table>
</form>
</html>
sendsms.php เป็นคำสั่งที่ใช้ในการเชื่อมต่อระหว่างเว็บกับตัวโปรแกรมเพื่อส่งSMS ไปให้ผู้รับที่ระบุในฟอร์มของsendsms_form.html
sendsms.php
<?php
header('Content-type: text/html; charset=utf-8');
?>
<?php
if ($submit=="Send")
{
$url='http://127.0.0.1:9333?'; // ที่อยู่เว็บของตัวโปรแกรม Ozeki Server
$url.="action=sendMessage";
$url.="&login=admin"; // ชื่อผู้ใช้งานของตัวโปรแกรม Ozeki server
$url.="&password=abc123"; // รหัสของตัวโปรแกรม Ozeki Server
$url.="&recepient=".urlencode($recepient);
$url.="&messageData=".urlencode($message);
file($url);
}
{
echo("<script> alert(' !!!! ส่งข้อความเรียบร้อยแล้วครับ !!!! '); window.location='sendsms_form.html';</script>");
exit();
}
?>
ส่วนสองโค้ดคือ sqlsmshandling_functions.php กับ sqlsmshandling.php เมื่อกดส่งไปแล้วข้อความที่ส่งสามารถนำมาลงในฐานข้อมูล Mysql ได้แต่ไม่สามารถส่ง SMS ไปยังมือถือได้
sqlsmshandling.php
<html>
<head>
<?php
include_once ("sqlsmshandling_functions.php");
?>
<title>SMS sending by PHP5 and MySQL</title>
</head>
<body>
<form action="" method="post">
<table border="0" align="center">
<tr>
<td colspan="2" align="center">
<font style="font-weight: bold; font-size: 16px;">เขียนข้อความ</font>
<br /><br />
</td>
</tr>
<tr>
<td valign="top">เบอร์ผู้รับ : </td>
<td>
<textarea name="textAreaRecipient" cols="40" rows="2"><?php echo ((isset($_POST["textAreaRecipient"])) ? ($_POST
["textAreaRecipient"]) : ("")); ?></textarea>
</td>
</tr>
<tr>
<td valign="top">ข้อความ : </td>
<td>
<textarea name="textAreaMessage" cols="40" rows="10"><?php echo ((isset($_POST["textAreaMessage"])) ? ($_POST
["textAreaMessage"]) : ("")); ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Send">
</td>
</tr>
<tr><td colspan='2' align='center'>
<?php
if (isset($_POST["textAreaRecipient"]) && $_POST["textAreaRecipient"] == "")
{
echo "<font style=\"color: red; font-weight: bold;\">Recipient field mustn't be empty!</font>";
}
else if (isset($_POST["textAreaRecipient"]) && $_POST["textAreaRecipient"] != "")
{
try
{
connectToDatabase();
if (insertMessage ($_POST["textAreaRecipient"], "SMS:TEXT", $_POST["textAreaMessage"]))
{
echo "<font style=\"color: red; font-weight: bold;\">Insert was successful!</font>";
}
closeConnection ();
}
catch (Exception $exc)
{
echo "Error: " . $exc->getMessage();
}
}
?>
</td></tr>
</table>
</form>
sqlsmshandling_functions.php
<?php
$connection = null; //a global variable. From function we access it: $GLOBALS["connection"]
function connectToDatabase()
{
$serverName = "127.0.0.1";
$userName = "root";
$password = "1234";
$databaseName = "sms";
//create connection and select database by given data
$GLOBALS["connection"] = mysql_connect($serverName, $userName, $password);
if ($GLOBALS["connection"] == null)
{
echo mysql_error() . "<br>";
return false;
}
try
{
mysql_select_db($databaseName);
}
catch (Exception $exc)
{
echo (mysql_error() . "<br>");
return false;
}
return true;
}
function closeConnection ()
{
try
{
mysql_close($GLOBALS["connection"]);
}
catch (Exception $exc)
{
//echo ($exc->getMessage() . "<br>");
}
}
function insertMessage ($recipient, $messageType, $messageText)
{
$query = "insert into ozekimessageout (receiver,msgtype,msg,status) ";
$query .= "values ('" . $recipient . "', '" . $messageType . "', '" . $messageText . "', 'send');";
mysql_query("SET NAMES UTF8");
$result = mysql_query ($query);
if (!$result)
{
echo (mysql_error() . "<br>");
return false;
}
return true;
}
function showOutgoingMessagesInTable()
{
$query = "select id,sender,receiver,senttime,receivedtime,operator,status,msgtype,msg from ozekimessageout;";
mysql_query("SET NAMES UTF8");
$result = mysql_query ($query);
if (!$result)
{
echo (mysql_error() . "<br>");
return false;
}
try
{
echo "<table border='1'>";
echo "<tr><td>ID</td><td>Sender</td><td>Receiver</td><td>Sent time</td><td>Received time</td><td>Operator</td>";
echo "<td>Status</td><td>Message type</td><td>Message text</td></tr>";
while ($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["sender"] . "</td>";
echo "<td>" . $row["receiver"] . "</td>";
echo "<td>" . $row["senttime"] . "</td>";
echo "<td>" . $row["receivedtime"] . "</td>";
echo "<td>" . $row["operator"] . "</td>";
echo "<td>" . $row["status"] . "</td>";
echo "<td>" . $row["msgtype"] . "</td>";
echo "<td>" . $row["msg"] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_free_result($result);
}
catch (Exception $exc)
{
echo (mysql_error() . "<br>");
return false;
}
return true;
}
function showIncomingMessagesInTable()
{
$query = "select id,sender,receiver,senttime,receivedtime,operator,msgtype,msg from ozekimessagein;";
mysql_query("SET NAMES UTF8");
$result = mysql_query ($query);
if (!$result)
{
echo (mysql_error() . "<br>");
return false;
}
try
{
echo "<table border='1'>";
echo "<tr><td>ID</td><td>Sender</td><td>Receiver</td><td>Sent time</td><td>Received time</td><td>Operator</td>";
echo "<td>Message type</td><td>Message text</td></tr>";
while ($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["sender"] . "</td>";
echo "<td>" . $row["receiver"] . "</td>";
echo "<td>" . $row["senttime"] . "</td>";
echo "<td>" . $row["receivedtime"] . "</td>";
echo "<td>" . $row["operator"] . "</td>";
echo "<td>" . $row["msgtype"] . "</td>";
echo "<td>" . $row["msg"] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_free_result($result);
}
catch (Exception $exc)
{
echo (mysql_error() . "<br>");
return false;
}
return true;
}
?>
สรุปสิ่งที่ต้องการให้ช่วยนะครับ
1. ต้องการให้นำโค้ด sendsms_form.html กับ sendsms.php ซึ่งสามารถส่งSMS ไปยังมือถือได้ แทรกเข้าไปอยู่ในโค้ด sqlsmshandling.php กับ sqlsmshandling_functions.php ซึ่งสามารถนำข้อความที่กรอกลงในฟอร์มบันทึกลงในฐานข้อมูล Mysql ได้ แต่ไม่สามารถส่งSMS ไปยังมือถือได้ จึงอยากให้ช่วยแก้ไขโค้ดเพื่อให้สามารถส่งSMS และทำการบันทึกลงในฐานข้อมูลได้ด้วยอะครับ
2. ต้องการให้แก้ไขโค้ด sendsms.php ให้สามารถส่งSMS ไปยังมือถือเป็นภาษาไทยได้ ซึ่งในที่นี้ยังส่งภาษาไทยไม่ได้ มันจะแสดงผลเป็นภาษาต่างดาวอะครับ
ขอบคุณมากๆครับผม ต้องการความช่วยเหลือจิงๆครับ 
Tag : PHP, MySQL, JavaScript

|
|
 |
 |
 |
 |
Date :
2011-09-15 21:51:10 |
By :
rockdie |
View :
2621 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
file($url);
}
{
echo("<script> alert(' !!!! ส่งข้อความเรียบร้อยแล้วครับ !!!! '); window.location='sendsms_form.html';</script>");
exit();
}
แทรก function สำหรับ insert ลงใน MySQL ตรงเงื่อนไขนี้ก็ได้ครับ
|
 |
 |
 |
 |
Date :
2011-09-16 09:10:05 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ๆทั้งสองครับ ถ้าไม่ได้ยังไงเด๋วมาแจ้งอีกนะคร้าบบบ ^^
|
 |
 |
 |
 |
Date :
2011-09-16 13:49:57 |
By :
rockdie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้เลยอะครับ ช่วยเรียบเรียงโค้ดให้นิดนึงนะครับ พี่ๆ ผมเพิ่งหัดอะครับ 
|
 |
 |
 |
 |
Date :
2011-09-16 20:37:02 |
By :
rockdie |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
insert ลงไหม ส่งได้หรือเปล่า
ตกลงส่งภาษาไทยไม่ได้อย่างเดียว หรือว่ายังไง
|
 |
 |
 |
 |
Date :
2011-09-17 01:27:05 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากกระทู้นี้ ผมของ ข้อมูล ตาราง และข้อมูลที่อยู่ในฟิวล์ ตัวอย่าง 4-5 ตัวอย่าง ขอคำแนะนำหน่อย ครับบบ
และ (
$url='http://127.0.0.1:9333?'; // ที่อยู่เว็บของตัวโปรแกรม Ozeki Server
$url.="action=sendMessage";
$url.="&login=admin"; // ชื่อผู้ใช้งานของตัวโปรแกรม Ozeki server
$url.="&password=abc123"; // รหัสของตัวโปรแกรม Ozeki Server
$url.="&recepient=".urlencode($recepient);
$url.="&messageData=".urlencode($messageText);
)
$url='http://127.0.0.1:9333?';// ตัวเลขสีแดง อ้างอิ้งจากจุดไหนครับ
$url.="&login=admin";//แล้ว login ตัวนี้ ต้องไป กำหนด ในโปรแกรม Ozeki ใช่ไหมครับ แต่ ผมติดตั้งแล้ว แต่เปิดไม่ได้ ครับ
$url.="&password=abc123";
|
ประวัติการแก้ไข 2018-01-23 10:20:46
 |
 |
 |
 |
Date :
2018-01-23 10:13:41 |
By :
baby137 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|