Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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
致命错误:在C:\qbapi\quickbooks php master\docs中对空成员函数getFreeFormNumber()的调用\_Php_Mysqli_Sql Insert_Quickbooks Online - Fatal编程技术网

致命错误:在C:\qbapi\quickbooks php master\docs中对空成员函数getFreeFormNumber()的调用\

致命错误:在C:\qbapi\quickbooks php master\docs中对空成员函数getFreeFormNumber()的调用\,php,mysqli,sql-insert,quickbooks-online,Php,Mysqli,Sql Insert,Quickbooks Online,我当时正在编写Keith Palmer Quickbooks PHP API。这一切都很好,并连接。示例查询以数组形式返回结果。我想做的是运行一个mysqli insert语句,它将运行结果数组并将记录保存在mysqli表中 $customers = $CustomerService->query($Context, $realm, "SELECT * FROM Customer"); foreach ($customers as $Customer) { //First, we w

我当时正在编写Keith Palmer Quickbooks PHP API。这一切都很好,并连接。示例查询以数组形式返回结果。我想做的是运行一个mysqli insert语句,它将运行结果数组并将记录保存在mysqli表中

$customers = $CustomerService->query($Context, $realm, "SELECT * FROM Customer");


foreach ($customers as $Customer)
{

//First, we will retrieve the ID, and strip out any spaces/characters.  
$id = $Customer->getId();
$str = preg_replace("/[^0-9]/","",$id);

    //Insert customer into customer tables. 
        $sql = "INSERT INTO Customers (CustomerID__kp, CustomerName, CustomerAddress1, CustomerCity, CustomerCounty, CustomerPostcode, CustomerTelephone) 

            VALUES ('".$str."', 
                    '".$Customer->getFullyQualifiedName()."',
                    '".$Customer->getBillAddr(0)->getLine1()."',
                    '".$Customer->getBillAddr(0)->getCity()."',
                    '".$Customer->getBillAddr(0)->getCountrySubDivisionCode()."',
                    '".$Customer->getBillAddr(0)->getPostalCode()."',
                    '".$Customer->getPrimaryPhone(0)->getFreeFormNumber()."'

                    )
                    ON DUPLICATE KEY 
                    UPDATE CustomerName = '".$Customer->getFullyQualifiedName()."',
                    CustomerAddress1 = '".$Customer->getBillAddr(0)->getLine1()."',
                    CustomerCity = '".$Customer->getBillAddr(0)->getCity()."',
                    CustomerCounty = '".$Customer->getBillAddr(0)->getCountrySubDivisionCode()."',
                    CustomerPostcode = '".$Customer->getBillAddr(0)->getPostalCode()."',
                    CustomerTelephone = '".$Customer->getPrimaryPhone(0)->getFreeFormNumber()."'
                    ";

        $conn->query($sql);

}
这是我的代码,它从Quickbooks中获取记录并将其保存在mysqli表中

$customers = $CustomerService->query($Context, $realm, "SELECT * FROM Customer");


foreach ($customers as $Customer)
{

//First, we will retrieve the ID, and strip out any spaces/characters.  
$id = $Customer->getId();
$str = preg_replace("/[^0-9]/","",$id);

    //Insert customer into customer tables. 
        $sql = "INSERT INTO Customers (CustomerID__kp, CustomerName, CustomerAddress1, CustomerCity, CustomerCounty, CustomerPostcode, CustomerTelephone) 

            VALUES ('".$str."', 
                    '".$Customer->getFullyQualifiedName()."',
                    '".$Customer->getBillAddr(0)->getLine1()."',
                    '".$Customer->getBillAddr(0)->getCity()."',
                    '".$Customer->getBillAddr(0)->getCountrySubDivisionCode()."',
                    '".$Customer->getBillAddr(0)->getPostalCode()."',
                    '".$Customer->getPrimaryPhone(0)->getFreeFormNumber()."'

                    )
                    ON DUPLICATE KEY 
                    UPDATE CustomerName = '".$Customer->getFullyQualifiedName()."',
                    CustomerAddress1 = '".$Customer->getBillAddr(0)->getLine1()."',
                    CustomerCity = '".$Customer->getBillAddr(0)->getCity()."',
                    CustomerCounty = '".$Customer->getBillAddr(0)->getCountrySubDivisionCode()."',
                    CustomerPostcode = '".$Customer->getBillAddr(0)->getPostalCode()."',
                    CustomerTelephone = '".$Customer->getPrimaryPhone(0)->getFreeFormNumber()."'
                    ";

        $conn->query($sql);

}
?>

我的问题是我得到了这个错误:

致命错误:在C:\qbapi\quickbooks php master\docs中对空成员函数getFreeFormNumber()的调用\


当我运行客户查询时,代码将客户保存在我的quickbooks中,并保存在我的mysqli中。但是由于某种原因,我得到了上面的错误

首先要测试值,然后执行函数调用并将结果分配给变量。然后在查询中使用变量:

foreach ($customers as $Customer)
{

//First, we will retrieve the ID, and strip out any spaces/characters.  
$id = $Customer->getId();
$str = preg_replace("/[^0-9]/","",$id);

// test customer phone number
if(isset($Customer->getPrimaryPhone(0))){
    $CustomerTelephone = $Customer->getPrimaryPhone(0)->getFreeFormNumber();
} else {
    $CustomerTelephone = '';
}

    //Insert customer into customer tables. 
        $sql = "INSERT INTO Customers (CustomerID__kp, CustomerName, CustomerAddress1, CustomerCity, CustomerCounty, CustomerPostcode, CustomerTelephone) 

            VALUES ('".$str."', 
                    '".$Customer->getFullyQualifiedName()."',
                    '".$Customer->getBillAddr(0)->getLine1()."',
                    '".$Customer->getBillAddr(0)->getCity()."',
                    '".$Customer->getBillAddr(0)->getCountrySubDivisionCode()."',
                    '".$Customer->getBillAddr(0)->getPostalCode()."',
                    '".$CustomerTelephone."'

                    )
                    ON DUPLICATE KEY 
                    UPDATE CustomerName = '".$Customer->getFullyQualifiedName()."',
                    CustomerAddress1 = '".$Customer->getBillAddr(0)->getLine1()."',
                    CustomerCity = '".$Customer->getBillAddr(0)->getCity()."',
                    CustomerCounty = '".$Customer->getBillAddr(0)->getCountrySubDivisionCode()."',
                    CustomerPostcode = '".$Customer->getBillAddr(0)->getPostalCode()."',
                    CustomerTelephone = '".$CustomerTelephone."'
                    ";

        $conn->query($sql);

}
警告
。即使是这样也不安全

$Customer->getPrimaryPhone(0)
为空或空,您需要修复该问题。说。即使是这样也不安全!当我从quickbooks中获取记录时,并不是所有记录都保存了电话号码。所以有些记录有电话号码,有些没有。在foreach循环$Customer->getPrimaryPhone(0)中,对于没有联系人号码的记录,可能为null,但如果联系人号码为空,则它将工作。我仍然想保存记录,但记录是否有联系电话。谢谢。如果答案解决了你的问题,请考虑接受答案。下面是如何返回此处并对勾号/复选标记执行相同操作,直到其变为绿色。这将通知社区,找到了解决方案。否则,其他人可能会认为问题仍然悬而未决,并可能希望发布(更多)答案。您将获得积分,并鼓励其他人帮助您。欢迎来到Stack!谢谢你的回复。我刚刚加上了你查电话号码的密码。当我点击触发代码的按钮时,我得到服务器错误。状态代码:500内部服务器错误…我之前确实添加了php(isset),但它给了我服务器错误。如果您回显$Customer->getPrimaryPhone(0),会发生什么情况?