Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中未定义的变量_Php_Mysql_Xml_Curl - Fatal编程技术网

PHP中未定义的变量

PHP中未定义的变量,php,mysql,xml,curl,Php,Mysql,Xml,Curl,我正在努力使用PHP中的cURL将XML请求发送到URL 首先,我只是想确保我的请求发送了正确的数据,所以这里是我的代码片段。一旦我知道我正在发送正确的数据,我将在稍后添加curl语句 以下是我目前的代码: $format = 'Y-m-j G:i:s'; $date = date ( $format ); $d = date ( $format, strtotime ( '-90 days' ) ); $sql = mysql_query("SELECT * FROM recurring

我正在努力使用PHP中的cURL将XML请求发送到URL

首先,我只是想确保我的请求发送了正确的数据,所以这里是我的代码片段。一旦我知道我正在发送正确的数据,我将在稍后添加curl语句

以下是我目前的代码:

$format = 'Y-m-j G:i:s'; 

$date = date ( $format );
$d = date ( $format, strtotime ( '-90 days' ) );

$sql = mysql_query("SELECT * FROM recurringPayments WHERE lastpmt <= '$d'");

$num_rows = mysql_num_rows($sql); 
echo $num_rows . " results found";

echo "<table style=\"border:1px solid green;\">
            <tr bgcolor=\"#bdd73b\">
            <th>ID</th>
            <th>Company Name</th>
            <th>Annual Subscription</th>
            <th>Package</th>
            <th>Cost</th>
            <th>Payer Ref</th>
            <th>Payment Ref</th>
            <th>Last Payment Date</th>
            </tr>";

            while ($row = mysql_fetch_array($sql))
            {
                echo "<tr>";
                echo "<td>" . $row['ID'] . "</td>";
                echo "<td>" . $row['compName'] . "</td>";
                echo "<td>" . $row['annualSub'] . "</td>";
                echo "<td>" . $row['package'] . "</td>";
                echo "<td>" . $row['cost'] . "</td>";               
                echo "<td>" . $row['payerref'] . "</td>";
                echo "<td>" . $row['pmtref'] . "</td>";
                echo "<td>" . $row['lastpmt'] . "</td>";
            }
            echo "</table>";        
while ($row = mysql_fetch_array($sql))
{
$xml_data ='<request type="receipt-in" timestamp="20030520151742">'.
       '<merchantid>test</merchantid>'.
           '<account>internet</account>'.
       '<orderid>transaction01</orderid>'.
       '<amount currency="EUR">'.$row['cost'].'</amount>'.
           '<payerref>'.$row['payerref'].'</payerref>'.
           '<paymentmethod>'.$row['pmtref'].'</paymentmethod>'.
           '<autosettle flag="1" />'.
           '<md5hash />'.
       '<sha1hash>c81377ac77b6c0a8ca4152e00cc173d01c3d98eb</sha1hash'.  
       '</request>';
}

 echo $xml_data;
$format='Y-m-j G:i:s';
$date=日期($format);
$d=日期($format,strottime(“-90天”);

$sql=mysql\u query(“SELECT*FROM recurringPayments,其中lastpmt您正在自始至终循环遍历结果集以构建html表,然后尝试再次循环遍历xml,即使您已经通过了集合的结尾。在同一个循环中构建这两个结果集


在循环之前将xml_数据设置为“”,然后使用xml_数据来构建它(或者甚至使用SimpleXML或XMLWriter而不是将其构建为字符串)

您的第二个循环通过已经循环的mysql\u查询,因此循环指针位于末尾,这意味着此代码永远不会运行。由于尚未运行$xml\u,因此数据未设置,当您尝试在末尾回显时,您会收到一条通知

while ($row = mysql_fetch_array($sql))
{
$xml_data ='<request type="receipt-in" timestamp="20030520151742">'.
       '<merchantid>test</merchantid>'.
           '<account>internet</account>'.
       '<orderid>transaction01</orderid>'.
       '<amount currency="EUR">'.$row['cost'].'</amount>'.
           '<payerref>'.$row['payerref'].'</payerref>'.
           '<paymentmethod>'.$row['pmtref'].'</paymentmethod>'.
           '<autosettle flag="1" />'.
           '<md5hash />'.
       '<sha1hash>c81377ac77b6c0a8ca4152e00cc173d01c3d98eb</sha1hash'.  
       '</request>';
}

在第二个while循环之前,当您迭代初始打印时,您正在向前移动结果集点。当您想要输出XML时,指针作为结果集的结尾,因此您需要重置它或在打印时构建XML

对于后者,请尝试以下方法:

$xmlData = '';
while ($row = mysql_fetch_array($sql))
{
    echo "<tr>";
    echo "<td>" . $row['ID'] . "</td>";
    echo "<td>" . $row['compName'] . "</td>";
    echo "<td>" . $row['annualSub'] . "</td>";
    echo "<td>" . $row['package'] . "</td>";
    echo "<td>" . $row['cost'] . "</td>";               
    echo "<td>" . $row['payerref'] . "</td>";
    echo "<td>" . $row['pmtref'] . "</td>";
    echo "<td>" . $row['lastpmt'] . "</td>";

    $xmlData .= '<request type="receipt-in" timestamp="20030520151742">'.
   '<merchantid>test</merchantid>'.
       '<account>internet</account>'.
   '<orderid>transaction01</orderid>'.
   '<amount currency="EUR">'.$row['cost'].'</amount>'.
       '<payerref>'.$row['payerref'].'</payerref>'.
       '<paymentmethod>'.$row['pmtref'].'</paymentmethod>'.
       '<autosettle flag="1" />'.
       '<md5hash />'.
   '<sha1hash>c81377ac77b6c0a8ca4152e00cc173d01c3d98eb</sha1hash'.  
   '</request>';
}

echo "</table>";
$xmlData='';
while($row=mysql\u fetch\u数组($sql))
{
回声“;
回显“$row['ID']”;
回显“$row['compName']”;
回显“$row['annualSub']”;
回显“$row['package']”;
回显“$row['cost']”;
回显“$row['payerref']”;
回显“$row['pmtref']”;
回显“$row['lastpmt']”;
$xmlData.=''。
“测试”。
“互联网”。
“transaction01”。
“.$row[‘成本’]”。
“.$row['payerref']”。
“.$row['pmtref']”。
''.
''.
'c81377ac77b6c0a8ca4152e00cc173d01c3d98eb试试这个:

   <?php

    $format = 'Y-m-j G:i:s'; 

    $date = date ( $format );
    $d = date ( $format, strtotime ( '-90 days' ) );

    $sql = mysql_query("SELECT * FROM recurringPayments WHERE lastpmt <= '$d'");

    $num_rows = mysql_num_rows($sql); 
    echo $num_rows . " results found";

    $xml_data = "";

    echo "<table style=\"border:1px solid green;\">
                <tr bgcolor=\"#bdd73b\">
                <th>ID</th>
                <th>Company Name</th>
                <th>Annual Subscription</th>
                <th>Package</th>
                <th>Cost</th>
                <th>Payer Ref</th>
                <th>Payment Ref</th>
                <th>Last Payment Date</th>
                </tr>";

                while ($row = mysql_fetch_array($sql))
                {
                    echo "<tr>";
                    echo "<td>" . $row['ID'] . "</td>";
                    echo "<td>" . $row['compName'] . "</td>";
                    echo "<td>" . $row['annualSub'] . "</td>";
                    echo "<td>" . $row['package'] . "</td>";
                    echo "<td>" . $row['cost'] . "</td>";               
                    echo "<td>" . $row['payerref'] . "</td>";
                    echo "<td>" . $row['pmtref'] . "</td>";
                    echo "<td>" . $row['lastpmt'] . "</td>";

                    $xml_data .='<request type="receipt-in" timestamp="20030520151742">'.
                           '<merchantid>test</merchantid>'.
                               '<account>internet</account>'.
                           '<orderid>transaction01</orderid>'.
                           '<amount currency="EUR">'.$row['cost'].'</amount>'.
                               '<payerref>'.$row['payerref'].'</payerref>'.
                               '<paymentmethod>'.$row['pmtref'].'</paymentmethod>'.
                               '<autosettle flag="1" />'.
                               '<md5hash />'.
                           '<sha1hash>c81377ac77b6c0a8ca4152e00cc173d01c3d98eb</sha1hash'.  
                           '</request>';


                }
                echo "</table>";        


     echo $xml_data;
$format='Y-m-j G:i:s';
$date=日期($format);
$d=日期($format,strottime(“-90天”);

$sql=mysql\u query(“从recurringPayments中选择*其中lastpmt Hi Mark,谢谢你的回答。这似乎可以解决问题。我有一个关于它的快速问题。我看不到XML标记,是吗?我只是想知道稍后在其中实现curl请求的时间。这有关系吗?谢谢:)XML标记在web浏览器中不可见…请使用浏览器的“查看源”选项查看它们
   <?php

    $format = 'Y-m-j G:i:s'; 

    $date = date ( $format );
    $d = date ( $format, strtotime ( '-90 days' ) );

    $sql = mysql_query("SELECT * FROM recurringPayments WHERE lastpmt <= '$d'");

    $num_rows = mysql_num_rows($sql); 
    echo $num_rows . " results found";

    $xml_data = "";

    echo "<table style=\"border:1px solid green;\">
                <tr bgcolor=\"#bdd73b\">
                <th>ID</th>
                <th>Company Name</th>
                <th>Annual Subscription</th>
                <th>Package</th>
                <th>Cost</th>
                <th>Payer Ref</th>
                <th>Payment Ref</th>
                <th>Last Payment Date</th>
                </tr>";

                while ($row = mysql_fetch_array($sql))
                {
                    echo "<tr>";
                    echo "<td>" . $row['ID'] . "</td>";
                    echo "<td>" . $row['compName'] . "</td>";
                    echo "<td>" . $row['annualSub'] . "</td>";
                    echo "<td>" . $row['package'] . "</td>";
                    echo "<td>" . $row['cost'] . "</td>";               
                    echo "<td>" . $row['payerref'] . "</td>";
                    echo "<td>" . $row['pmtref'] . "</td>";
                    echo "<td>" . $row['lastpmt'] . "</td>";

                    $xml_data .='<request type="receipt-in" timestamp="20030520151742">'.
                           '<merchantid>test</merchantid>'.
                               '<account>internet</account>'.
                           '<orderid>transaction01</orderid>'.
                           '<amount currency="EUR">'.$row['cost'].'</amount>'.
                               '<payerref>'.$row['payerref'].'</payerref>'.
                               '<paymentmethod>'.$row['pmtref'].'</paymentmethod>'.
                               '<autosettle flag="1" />'.
                               '<md5hash />'.
                           '<sha1hash>c81377ac77b6c0a8ca4152e00cc173d01c3d98eb</sha1hash'.  
                           '</request>';


                }
                echo "</table>";        


     echo $xml_data;
$format = 'Y-m-j G:i:s'; 

$date = date ( $format );
$d = date ( $format, strtotime ( '-90 days' ) );

$sql = mysql_query("SELECT * FROM recurringPayments WHERE lastpmt <= '$d'");

$num_rows = mysql_num_rows($sql); 
echo $num_rows . " results found";

$xml_data = ''; // init empty

echo "<table style=\"border:1px solid green;\">
            <tr bgcolor=\"#bdd73b\">
            <th>ID</th>
            <th>Company Name</th>
            <th>Annual Subscription</th>
            <th>Package</th>
            <th>Cost</th>
            <th>Payer Ref</th>
            <th>Payment Ref</th>
            <th>Last Payment Date</th>
            </tr>";

while ($row = mysql_fetch_array($sql))
{
   echo "<tr>";
   echo "<td>" . $row['ID'] . "</td>";
   echo "<td>" . $row['compName'] . "</td>";
   echo "<td>" . $row['annualSub'] . "</td>";
   echo "<td>" . $row['package'] . "</td>";
   echo "<td>" . $row['cost'] . "</td>";               
   echo "<td>" . $row['payerref'] . "</td>";
   echo "<td>" . $row['pmtref'] . "</td>";
   echo "<td>" . $row['lastpmt'] . "</td>";

   $xml_data .='<request type="receipt-in" timestamp="20030520151742">'.
                       '<merchantid>test</merchantid>'.
                           '<account>internet</account>'.
                       '<orderid>transaction01</orderid>'.
                       '<amount currency="EUR">'.$row['cost'].'</amount>'.
                           '<payerref>'.$row['payerref'].'</payerref>'.
                           '<paymentmethod>'.$row['pmtref'].'</paymentmethod>'.
                           '<autosettle flag="1" />'.
                           '<md5hash />'.
                       '<sha1hash>c81377ac77b6c0a8ca4152e00cc173d01c3d98eb</sha1hash'.  
                       '</request>';

}
echo "</table>";        

echo $xml_data;