Pages: [1]
  Print  
Author Topic: Zip code bug. If it starts with a 0 (zero) it gets tossed away.  (Read 573 times)
ugzdntktdle
Newbie
*
Offline Offline

Posts: 5


View Profile Email
« on: March 11, 2010, 04:21:29 AM »

If you live in a US state that's zip code start with a zero, it gets tossed away. For example:

Zip code: 01234
After it is saved it displays it as: 1234

I did a select zip from phprealty_property in mysql and it is displayed as 1234 instead of 01234 also. I used UPDATE in mysql to place the correct zip of 01234, and it does accept it. When you use mysql and so a select again, it looks OK, however if you edit it in phpRealty (version 0.05) it will change it back to 1234 tossing the zero.

It appears like phpRealty is somewhere along the way changing the zip code of 01234 to an integer which would cause it to toss the zero. That's my guess.

Anyone have a code change to fix this? Thank you!
Logged
ugzdntktdle
Newbie
*
Offline Offline

Posts: 5


View Profile Email
« Reply #1 on: March 12, 2010, 02:11:15 AM »

I have the fix for this. This isn't official, it is just me mucking around and I was able to fix it. This is what I did, edit phprealty.class.php which can be found at:

manager/includes/phprealty.class.php

Around Line 387 you see:

foreach($fields as $key=>$value) {
        $sql .= "`".$key."`=";
        if (is_numeric($value)) $sql .= $value.",";
        else $sql .= "'".$value."',";

Replace the above with this:

foreach($fields as $key=>$value) {
        $sql .= "`".$key."`=";
        // if (is_numeric($value)) $sql .= $value.","; // old code, has bug to make zip 01234 to 1234.
        if (is_numeric($value) && $key!="zip") $sql .= $value.",";
        else $sql .= "'".$value."',";

The problem was that there weren't quotes around the zip code value when it was being done as an UPDATE to MySQL. If a value is text, it needs quotes around it. If it is numeric, it doesn't. However, the except is that a Zip Code is not a numeric value, it is really text. So if a zip code was 01234, it was like entering 01234 into a calculator since it would drop the zero.

I hope this helps others. As I said, this isn't official, this is just my fix on this. If you have a better fix or comments on this to help improve it, please post!
Logged
ugzdntktdle
Newbie
*
Offline Offline

Posts: 5


View Profile Email
« Reply #2 on: March 12, 2010, 03:02:37 AM »

Sorry, the code above the previous one needs to be changed too:

  function putIntTableRow($fields="", $into="") {
  // function to put a row into ANY internal database table
  // INSERT's a new table row into ANY internal phpRealty database table. No data validation is performed.
  // $fields = a $key=>$value array: $fields=("name"=>$name,"email"=$email,"age"=>$age)
  // $into = name of the internal phpRealty table which will receive the new data row without database name or table prefix: $into="user_messages"
  // Returns FALSE on failure.
    if(($fields=="") || ($into=="")){
      return false;
    } else {
      $tbl = $this->db.$into;
      $sql = "INSERT INTO $tbl SET ";
      foreach($fields as $key=>$value) {
        $sql .= "`".$key."`=";
        // if (is_numeric($value)) $sql .= $value.","; // old code, has bug to make zip 01234 to 1234.
        if (is_numeric($value) && $key!="zip") $sql .= $value.",";
        else $sql .= "'".$value."',";
      }
      $sql = rtrim($sql,",");
          $sql = trim($sql);
      $sql .= ";";
      $result = $this->dbQuery($sql);
      return $result;
    }
  }
Logged
Pages: [1]
  Print  
 
Jump to: