0

我尝试将一些数据从本地数据库发送到数据库服务器。本地数据库中的表名称为“inbox”。我将“收件箱”中的数据转换为 XML 这是用于inboek2.php本地 pc 中此脚本的代码 ( )

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('sms');

header('Content-Type: text/xml');
echo "&lt;?xml version='1.0'?&gt;";

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&#40;'http://localhost/baca/inboek2.php'&#41;;
    foreach($dataxml->data as $data)
    {

       $id = $data->id;
       $tgl = $data->tgl;
       $nope = $data->nope;
       $isi = $data->isi;

       $curlHandle = curl_init();
       $curResponse = curl_exec&#40;$curlHandle&#41;;
       curl_setopt($curlHandle, CURLOPT_URL, 'http://www.adibiken.com/SEM/kir.php');
       curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'id='.$id.'&amp;tgl='.$tgl.'&amp;nope='.$nope.'&amp;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&#40;$curlHandle&#41;;
       curl_close($curlHandle);
       echo $curResponse;
    }
    ?>

最后一个,这是kir.phpHOSTING中的代码

<?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是否已成功发送到数据库而没有空记录?

如果我删除另一个变量至少仍然是最后一个变量,则数据已成功发送空白记录,这很奇怪,,,,,

4

2 回答 2

0

您可以尝试检查每个变量的长度,以确保它们在插入之前不为空。这可以使用 strlen 或 mb_strlen 来完成。

http://www.php.net/manual/en/function.mb-strlen.php

http://php.net/manual/en/function.strlen.php

于 2013-02-08T09:18:34.167 回答
0

您可以通过以下方式检查:

if(isset($_POST['id'])){
    $id = $_POST['id']; 
}else{
    //the POST variable was empty, do something.
}
于 2013-02-08T09:00:27.883 回答