Solved

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

Posted on 2013-06-21
7
301 Views
Last Modified: 2013-06-21
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

0
Comment
Question by:ditallop
  • 4
  • 2
7 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 39266405
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.
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 39266406
Your line 6 is

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

but should be

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

=> instead of =

Cheers
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 39266410
I see also a bad value for form id which should not  contain white spaces: you should modify it to "MedicareSuppliers"

Cheers
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:ditallop
ID: 39266534
@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?
0
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 39266619
Php is smart enough to understand by itself is a value is a string or a number, so you can be happy leaving Php does the work for you.

That said, your question (what is the best way...) is too vague for me. If you need more help, you should post an example of the array you need to process and say exactly what you want to get. In addition, I don't have any idea about what GetSupplierByZipCode() method does. AFAIK, your code should work fine once you fix the error mentioned above :)

Cheers
0
 

Author Comment

by:ditallop
ID: 39266962
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.
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 39267628
Thanks for points and good luck with your project.

Marco
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now