mysqli - Fatal error: Call to a member function getFreeFormNumber() on null in C:\qbapi\quickbooks-php-master\docs\ -


i working on keith palmer quickbooks php api. works fine , connects. example queries return result in arrays. wanted run mysqli insert statement run through results array , save records in mysqli table.

here code get's records quickbooks , save in mysqli table.

$customers = $customerservice->query($context, $realm, "select * customer");   foreach ($customers $customer) {  //first, retrieve id, , strip out spaces/characters.   $id = $customer->getid(); $str = preg_replace("/[^0-9]/","",$id);      //insert customer customer tables.          $sql = "insert 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);  } 

?>

my question error:

fatal error: call member function getfreeformnumber() on null in c:\qbapi\quickbooks-php-master\docs\

when run customer queries, code gets customers saved in quickbooks, , save in mysqli. reason above error.

you want test value first, perform function call , assign result variable. use variable in query:

foreach ($customers $customer) {  //first, retrieve id, , strip out 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 customer tables.          $sql = "insert 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);  } 

warning!

little bobby says your script @ risk sql injection attacks.. escaping string not safe!


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -