when i run this code..blank screen ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smilesmita
Forum Commoner
Posts: 30
Joined: Thu May 24, 2007 1:52 pm

when i run this code..blank screen ?

Post by smilesmita »

hi there,
i have written this code where i get teh xml file from ups servers,parse it and then insert the values in Database from the xml array which i get along the way.But when i run the code... i get a blank screen...it doesnt attempt to contact server...dont know what is must be wrong.looks like its not initiating the init fucntion.any ideas?
here is the code:

Code: Select all

<?php
require_once 'lib.xml.php';
require_once 'inc.config.php';
class ups_xml {

var $wo_fields = array (
"SubscriptionFile" => "text",
"FileName" => "text",
"StatusType" => "text",
"Code" => "text",
"Description" => "text",
"Manifest" => "text",
"Shipper" => "text",
"ShipperNumber" => "text",
"Address" => "text",
"ShipTo" => "text",
"ConsigneeName" => "text",
"AddressLine1" => "text",
"City" => "text",
"StateProvinceCode" => "text",
"PostalCode" => "text",
"CountryCode" => "text",
"ReferenceNumber" => "text",
"Service" => "text",
"Code" => "text",
"PickupDate" => "text",
"ScheduledDeliveryDate" => "text",
"Package " => "text",
"Activity " => "text",
"Date" => "text",
"Time" => "text",
"TrackingNumber" => "text",
"PackageServiceOptions" => "text",
"BillToAccount" => "text",
"Option" => "text",
"Number" => "text"
);


Function Init()
{
$fp =@fsockopen("ssl://www.ups.com",443, $errno, $errstr);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else
$upstr = "POST /ups.app/xml/QVEvents HTTP/1.0\r\n";
$upstr .= "Host: http://www.ups.com\r\n";
$upstr .= "Content-Type: application/xml\r\n";
$upstr .= "Content-Length: 512\r\n\r\n";
$upstr .= '<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>xxxx</AccessLicenseNumber>
<UserId>xxxb</UserId>
<Password>cxxxr</Password>
</AccessRequest>
<?xml version="1.0" encoding="UTF-8"?>
<QuantumViewRequest xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>Test XML</CustomerContext>
<XpciVersion>1.0007</XpciVersion>
</TransactionReference>
<RequestAction>QVEvents</RequestAction>
</Request>
</QuantumViewRequest>';

fputs($fp,$upstr,strlen($upstr));

while (!feof($fp)) {

$soap_in .= fgets($fp,100);
}
$data = preg_replace('/.*?\r\n\r\n(.*)/s', '$1', $soap_in);
}

Function Parse_File($import_file)
{
global $post;
$lastpo = -1;
$import = array();

// echo "<xmp>$data</xmp>";
$xmldata = XML_To_Array($data);
$this->Walk_XML($xmldata);
}
Function Write_WO ($wo)
{
global $db;
$this->Add_Rec($query_type="insert","am_ups_xml",$this- >wo_fields,$wo);

}
Function Add_Rec( $query_type = "insert", $table, $fields, $data)
{
global $db;

foreach($fields AS $field => $type) {
if ( IsSet($data[$field]) || $query_type != "update" ) {
$value = $data[$field];
switch($type) {
case 'id':
if ( IsBlank($value) )
$value = 0;
else
$value = intval($value);
break;
case 'text':
if ( IsBlank($value) )
$value = "NULL";
else
$value = "'" . addslashes($value) . "'";
break;
case 'int':
if ( IsBlank($value) )
$value = "NULL";
else
$value = intval(preg_replace("/,/", "", $value));
break;
case 'decimal':
if ( IsBlank($value) )
$value = "NULL";
else
$value = doubleval(preg_replace("/,/", "", $value));
break;
case 'timestamp':
$y = $mo = $d = $h = $mi = $s = 0;

$timestamp_rx = "/^([ 0-9]*)\/([ 0-9]*)\/([ 0-9]*) " .
"([ 0-9]*)Sad[ 0-9]*) ([AP])M$/";
$date_rx = "/^([ 0-9]*)\/([ 0-9]*)\/([ 0-9]*)/";

$matches = array();

if ( preg_match($timestamp_rx, $value, $matches ) ) {
$mo = intval(trim($matches[1]));
$d = intval(trim($matches[2]));
$y = 2000 + intval(trim($matches[3]));
$h = intval(trim($matches[4]));
$mi = intval(trim($matches[5]));
$s = 0;
if ( $matches[6] == "P" )
$m += 12;
} elseif ( preg_match($date_rx, $value, $matches ) ) {
$mo = intval(trim($matches[1]));
$d = intval(trim($matches[2]));
$y = 2000 + intval(trim($matches[3]));
}

if ( $y > 2050 )
$y = $y - 100;

if ( $mo && $d ) {
$value = sprintf(
"'%04d-%02d-%02d %02d:%02d:%02d'::TIMESTAMP",
$y, $mo, $d, $h, $mi, $s);
} else {
$value = "NULL";
}
break;
case 'boolean':
if ( isBlank($value) )
$value = "NULL";
else
$value = ($value?"True":"False") . "::BOOLEAN";
break;
}
$keyval[$field] = $value;
$updates[] = "$field = $value";
$insert_fields[] = $field;
$insert_values[] = $value;
}
}

if ( $query_type == "insert" ) {
$query = "INSERT INTO $table ( " .
join(",", $insert_fields) . " ) VALUES ( " .
join(",", $insert_values) . " );";
}
$r = $db->Query($query);
}



Function Walk_XML($xmldata)
{
if ( Is_Array($xmldata) ) {
foreach ( $xmldata AS $k => $v ) {
if ( Is_Array($v) ) {
if ( $v["TAG"] == "SubscriptionFile" ) {
$this->Parse_XML_WO($v);
return;
}
$this->Walk_XML($v);
}
}
}
return;
}
Function Parse_XML_WO($woarr)
{
$wo = array();


if ( Is_Array($woarr)) {
foreach ( $woarr AS $k => $v ) {
if ( Is_Array($v) && isset($v["TAG"]) ) {
switch ( $v["TAG"] ) {
case "SubscriptionFile":
$wo["SubscriptionFile"] = $v["VALUE"];
break;
case "FileName":
$wo["FileName"] = $v["VALUE"];
break;
case "StatusType":
$wo["StatusType"] = $v["VALUE"];
break;
case "Code":
$wo["Code"] =$v["VALUE"];
break;
case "Description":
$wo["Description"] = $v["VALUE"];
break;
case "Manifest":
$wo["Manifest"] = $v["VALUE"];
break;
case "Shipper":
$wo["Shipper"] = $v["VALUE"];
break;
case "Name":
$wo["Name"] = $v["VALUE"];
break;
case "ShipperNumber":
$wo["ShipperNumber"] = $v["VALUE"];
break;
case "Address":
$wo["Address"] =$v["VALUE"];
break;
case "AddressLine1":
$wo["AddressLine1"] = $v["VALUE"];
break;
case "City":
$wo["City"] =$v["VALUE"];
break;
case "StateProvinceCode":
$wo["StateProvinceCode"] = doubleval($v["VALUE"]);
break;
case "PostalCode":
$wo["PostalCode"] = doubleval($v["VALUE"]);
break;
case "CountryCode":
$wo["CountryCode"] = doubleval($v["VALUE"]);
break;
case "ShipTo":
$wo["ShipTo"] = doubleval($v["VALUE"]);
break;
case "Address":
$wo["Address"] = doubleval($v["VALUE"]);
break;
case "ConsigneeName":
$wo["ConsigneeName"] = $v["VALUE"];
break;
case "ReferenceNumber":
$wo["ReferenceNumber"] = doubleval($v["VALUE"]);
break;
case "Value":
$wo["Value"] = doubleval($v["VALUE"]);
break;
case "Service":
$wo["Service"] = doubleval($v["VALUE"]);
break;

case "PickupDate":
$wo["PickupDate"] = $v["VALUE"];
break;
case "ScheduledDeliveryDate":
$wo["ScheduledDeliveryDate"] = $v["VALUE"];
break;
case "Package":
$wo["Package"] =$v["VALUE"];
break;
case "Activity":
$wo["Activity"] = $v["VALUE"];
break;
case "Date":
$this->$v["VALUE"];
break;
case "Time":
$wo["Time"] = $v["VALUE"];
break;
case "TrackingNumber":
$wo["TrackingNumber"] = $v["VALUE"];
break;
case "PackageServiceOptions":
$wo["PackageServiceOptions"] = $v["VALUE"];
break;
case "BillToAccount":
$wo["BillToAccount"] = $v["VALUE"];
break;
case "Option":
$wo["Option"] = $v["VALUE"];
break;
case "Number":
$wo["Number"] = $v["VALUE"];
break;


}
}
}
}
$this->Write_WO($wo);
}

}

?>
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

do you need curly braces around your Else Statement within your Init function??

Other than that, I'd strongly suggest checking all curly braces finish in the right spot, if at all, that looks kinda confusing...
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

are you using apache? if so, go to apache\logs\error.log. the last line in the file should be a PHP parse error. what does the error say?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

As iknownothing said, your else statement seems to be missing the else "block".
Might as well return FALSE if fsockopen returned FALSE

Code: Select all

function Init()
 {
        $fp = @fsockopen("ssl://www.ups.com", 443, $errno, $errstr);
        if (!$fp) 
         {
                echo "$errstr ($errno)<br />\n";
                return FALSE;
         }

        $upstr  = "POST /ups.app/xml/QVEvents HTTP/1.0\r\n";
        $upstr .= "Host: http://www.ups.com\r\n";
        $upstr .= "Content-Type: application/xml\r\n";
        $upstr .= "Content-Length: 512\r\n\r\n";
        $upstr .= '<?xml version="1.0"?>
        <AccessRequest xml:lang="en-US">
        <AccessLicenseNumber>xxxx</AccessLicenseNumber>
        <UserId>xxxb</UserId>
        <Password>cxxxr</Password>
        </AccessRequest>
        <?xml version="1.0" encoding="UTF-8"?>
        <QuantumViewRequest xml:lang="en-US">
        <Request>
        <TransactionReference>
        <CustomerContext>Test XML</CustomerContext>
        <XpciVersion>1.0007</XpciVersion>
        </TransactionReference>
        <RequestAction>QVEvents</RequestAction>
        </Request>
        </QuantumViewRequest>';
        
        fputs($fp,$upstr,strlen($upstr));
        
        while (!feof($fp)) 
         {
                $soap_in .= fgets($fp,100);
         }

        $data = preg_replace('/.*?\r\n\r\n(.*)/s', '$1', $soap_in);
 }
Post Reply