我尝试从数据库本地向数据库服务器发送一些数据。
数据库本地中的表名称是“收件箱”。
“收件箱”中的数据我转换为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
(本地pc中的这个脚本):
<?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;
}
?>
和最后一个,这是HOSTING中kir.php
的代码
<?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);
?>
PROBELM:我该怎么做才能使变量:$id , $tgl, $isi, $nope
已经成为SUCCESFULL发送到数据库而没有空的记录???
如果我删除另一个变量至少仍然是最后一个变量数据已成功发送whitout空记录,, 这很奇怪,,,,,
答案 0 :(得分:0)
您可以通过以下方式查看:
if(isset($_POST['id'])){
$id = $_POST['id'];
}else{
//the POST variable was empty, do something.
}
答案 1 :(得分:0)
您可以尝试检查每个变量的长度,以确保在插入之前它们不是空的。这可以使用strlen或mb_strlen来完成。