# PHP/Ajax Problem

**URL:** <https://forum.kirupa.com/t/php-ajax-problem/222265>\
**Category:** programming\
**Created:** [April 12, 2007, 2:22am UTC](https://forum.kirupa.com/t/php-ajax-problem/222265 "2007-04-12T02:22:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorren\_biffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/lorren_biffin/32/2726_2.png) [@lorren\_biffin](https://forum.kirupa.com/u/lorren_biffin)\
**Post date:** [April 12, 2007, 2:22am UTC](https://forum.kirupa.com/t/php-ajax-problem/222265/1 "2007-04-12T02:22:45Z")

</div>

Crap, accidentally put this in the wrong forum. Will a mod please move this to Server Side Programming? Thanks! 🙂

I’m testing a class/sql library i found for parsing zip codes and returning info about them.

Here’s my code:

**getinfo.php**

```auto

<?php

require_once('zipcode.class.php'); // zip code class

mysql_pconnect('localhost','root','steel49') or die(mysql_error()); 
mysql_select_db('zip_db') or die(mysql_error()); 

$z = new zipcode_class;

function safehtml($s)
{
    $s=str_replace("&", "&amp;", $s);
    $s=str_replace("<", "&lt;", $s);
    $s=str_replace(">", "&gt;", $s);
    $s=str_replace("'", "&apos;", $s);
    $s=str_replace("\"", "&quot;", $s);
    return $s;
}

$zipCode = safehtml($_POST["zipcd"]);

echo safehtml($_POST["zipcd"]);

$details = $z->get_zip_details($zipCode);

if (empty($details)) echo 'Error: '.$z->last_error;
else {
   foreach ($details as $key => $value) {
      $key = str_replace('_',' ',$key);
      $key = ucwords($key);
      echo "$key:&nbsp;$value<br>";
   } 
}

?>

```

\*\*index.html  
\*\*

```auto

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script src="pageax.js" type="text/javascript"></script>
    <style type="text/css">
    body {
        padding: 20px;
        margin: 0;
        font-family: Arial, sans-serif;
        font-size: 10pt;
    }
    </style>
</head>
<body>

<p><strong>Get Info About a ZIP Code:</strong><br />
<form action="javascript:gotoPage('getinfo.php')" method="post">
    <input type="text" name="zipcd" /><br />
    <input type="submit" />
</form>
</p>

<p><div id="content"></div></p>

</body>
</html>

```

Everything works fine(loads getinfo.php into the div and returns correctly), BUT…

I’ve been able to narrow the problem down to the use of $\_POST to pass in the zip code, as I get an error unless I set the ZIP manually in getinfo.php. EX: I get it working correctly using:

```auto
$zipCode = "97501";

```

Instead of:

```auto
$zipCode = safehtml($_POST["zipcd"]);

```

So, I’m assuming that PageAX just dropping(or not even sending) the $\_POST info and is returning the error because $zipCode doesn’t contain any info.

Any ideas on how to solve my little problem?

Thanks a whole bunch and _high five_ in advance! 🙂
