Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-06-21
7
306 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 31

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 31

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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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 31

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 31

Expert Comment

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

Marco
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 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