我尝试将一些数据从本地数据库发送到数据库服务器。本地数据库中的表名称为“inbox”。我将“收件箱”中的数据转换为 XML 这是用于inboek2.php
本地 pc 中此脚本的代码 ( )
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('sms');
header('Content-Type: text/xml');
echo "<?xml version='1.0'?>";
echo "<inbox>";
$query = "SELECT inbox.id, ReceivingDateTime, SenderNumber, TextDecoded FROM inbox ORDER BY inbox.id";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil))
{
// representasi data sms
echo "<data>";
echo "<id>".$data['id']."</id>";
echo "<tgl>".$data['ReceivingDateTime']."</tgl>";
echo "<nope>".$data['SenderNumber']."</nope>";
echo "<isi>".$data['TextDecoded']."</isi>";
echo "</data>";
}
echo "</inbox>";
?>
脚本的结果inboek2.php
,会被脚本捕获proses.php
这是用于代码proses.php
(本地电脑中的此脚本):
<?php
// koneksi ke mysql di server localhost
mysql_connect('localhost', 'root', '');
mysql_select_db('sms');
// baca data XML dari script inboek2.php yang digenerate oleh data.php
$dataxml = simplexml_load_file('http://localhost/baca/inboek2.php');
foreach($dataxml->data as $data)
{
$id = $data->id;
$tgl = $data->tgl;
$nope = $data->nope;
$isi = $data->isi;
$curlHandle = curl_init();
$curResponse = curl_exec($curlHandle);
curl_setopt($curlHandle, CURLOPT_URL, 'http://www.adibiken.com/SEM/kir.php');
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'id='.$id.'&tgl='.$tgl.'&nope='.$nope.'&isi='.$isi);
//and if i delete another variable atleast still the last one variable the data has been sucessfull sending whitout empty record ,,this is weird,,,,,
curl_setopt($curlHandle, CURLOPT_HEADER, 0);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandle, CURLOPT_TIMEOUT,30);
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_exec($curlHandle);
curl_close($curlHandle);
echo $curResponse;
}
?>
最后一个,这是kir.php
HOSTING中的代码
<?php
include "koneksi.php";
$id = $_POST['id'];
$tgl = $_POST['tgl'];
$isi = $_POST['isi'];
$nope = $_POST['nope'];
// query insert data ke mysql
$quer = "INSERT INTO `adibiken_sem`.`inbox` (`id`,`tgl` ,`isi` ,`nope`) VALUES ( '".$id."','".$tgl."', '".$isi."', '".$nope."')";
mysql_query($quer);
?>
问题:我应该怎么做才能使变量:$id , $tgl, $isi, $nope
是否已成功发送到数据库而没有空记录?
如果我删除另一个变量至少仍然是最后一个变量,则数据已成功发送空白记录,这很奇怪,,,,,