[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-06-21
7
Medium Priority
?
322 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:Paula DiTallo
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Paula DiTallo
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 2000 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:Paula DiTallo
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

656 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