Link to home
Start Free TrialLog in
Avatar of Paula DiTallo
Paula DiTalloFlag for United States of America

asked on

php: please review... can't find error..

Techies--
No errors, but nothing shows up on the page. I've been looking at it too long to identify the error--please review.  All this code is trying to do is return simple string values from a remote web service.

<?php

if ($_POST['zipn'] != ''){
  $zipn = (string) $_POST['zipn'];
  $client = new SoapClient("http://www.webservicex.net/medicareSupplier.asmx?WSDL");
  $result = $client->GetSupplierByZipCode(array('izipn' = $zipn));
  // Note that $array contains the result of the traversed object structure
  $array = $result->GetSupplierByZipCodeResult->tSupplierData;

  print "
<table border='2'>
  <tr>
    <th>SupplierNumber</th>
    <th>CompanyName</th>
    <th>Address1</th>
    <th>Address2</th>
    <th>City</th>
    <th>State</th>
    <th>Zip</th>
    <th>ZipPlus4</th>
    <th>Telephone</th>
    <th>IsSupplierParticipating</th>
  </tr>
";

  foreach($array as $k=>$v){
    print "
      <tr>
        <td align='right'>" . ($k+1) . "</td>
          <td>" . $v->sSupplierNumber . "</td>
		      <td align='right'>" . $v->sCompanyName . "</td>
		      <td align='right'>" . $v->sAddress1 . "</td>
		      <td align='right'>" . $v->sAddress2 . "</td>
		      <td align='right'>" . $v->sCity     . "</td>
		      <td align='right'>" . $v->sState    . "</td>
		      <td align='right'>" . $v->sZip      . "</td>
		      <td align='right'>" . $v->sZipPlus4 . "</td>
		      <td align='right'>" . $v->sTelephone . "</td>
		      <td align='right'>" . $v->sIsSupplierParticipating . "</td>
	  </tr>";

}

print "</table>";
}
else {

?>

<form id="Medicare Suppliers" action="index.php" method="post">
Which zip code are you interested in researching? (Type in a 5 digit zip code).
<input id="zipn" name="zipn" size="5" type="text" value="06512" />
<input id="submit" name="submit" type="submit" value="submit" />
</form>

<?php

}

?>

Open in new window

Avatar of gplana
gplana
Flag of Spain image

This is what I do when this happens to me:

try to comment all of your code and add an echo command at the end. Something like:

<?php
/*

all your php code here

*/
echo 'Hi!';
?>

you will see the message "Hi!" on the screen.

Then try to uncomment line by line until you found the error.

Another solution is to set the display mode to show errors, but some servers doesn't allow this, so on this case I use the technique I described above about commenting/uncommenting code.

Hope it helps.
Your line 6 is

$result = $client->GetSupplierByZipCode(array('izipn' = $zipn));

but should be

$result = $client->GetSupplierByZipCode(array('izipn' => $zipn));

=> instead of =

Cheers
I see also a bad value for form id which should not  contain white spaces: you should modify it to "MedicareSuppliers"

Cheers
Avatar of Paula DiTallo

ASKER

@margusG -- great catches!

  $result = $client->GetSupplierByZipCode(array('izipn' => $zipn));  

I think this is the line where things go wrong, now that you spotted it-- the other method i was working with was by supplier id--which was convenient since i had an integer to work with while cycling thru an array...

What is the best way to work with this array of strings (zip codes) that look like numbers?
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks margus--I come from the c# world -- i would have had to have create a integer/string-key pair to cycle through the array.
Thanks for points and good luck with your project.

Marco