Jump to content


Photo

Update problem with numbers and text


  • Please log in to reply
4 replies to this topic

#1 hessie

hessie
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 March 2003 - 12:23 PM

Hi all,

when I read a table, edit a value and want to write that back to the table in another field, there goes something wrong when the selected field contains \"123456789AB\". However \"123456\" goes alright.


$data_res = db_query("SELECT number, number2 FROM item") or db_die();

while ($data_row = db_fetch_row($data_res)) {

         $string2 = $data_row[0];

         $string2 = str_replace(".", "", $string2);

         $result=db_query("update item set number2=$string2 where number=$data_row[0]") or db_die();

         if ($result) {echo "Article $data_row[0] with new $string2  is updated";}

         else {echo "-- > Article $data_row[0] with new $string2 is not updated";}

         echo "<BR>";

         }


I fetch the value \"1234.5678AA\", this result in $string2 as \"12345678AA\" but MySql gives an error \"There is something wring in the used syntax at \'AA\' in row 1\". :?

When I fetch a value of \"1234.5678\", $string2 will result with \"12345678\" and the update goes fine.

The details of \'number2\' field is text.

Please HELP!!!!

thanks,

Henk.

#2 ystrigathe

ystrigathe
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationCologne / Germany

Posted 19 March 2003 - 05:01 PM

just try it with \'\':

update item set number2=\'$string2\' where

...

#3 hessie

hessie
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 March 2003 - 11:00 AM

just try it with \'\':

update item set number2=\'$string2\' where

...


Thanks.... But i tried it with \'\".$string2.\"\' and \'$string2\' etc....
Unfort. no dice.

Field is a VARCHAR of 16 of length.

Any other ideas?

THANKS!

#4 hessie

hessie
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 March 2003 - 11:26 AM

just try it with \'\':

update item set number2=\'$string2\' where

...


Thanks.... But i tried it with \'\".$string2.\"\' and \'$string2\' etc....
Unfort. no dice.

Field is a VARCHAR of 16 of length.

Any other ideas?

THANKS!


I found it....

when i use this CHAR(\'$string2\') for every field, it works.
I still have an issue, that my data is not being updated....

When I find a solution, i also post it here.... When someone has a solution, i hope you can reply this mesage.

Thanks in advance....

#5 hessie

hessie
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 March 2003 - 11:35 AM

just try it with \'\':

update item set number2=\'$string2\' where

...


Thanks.... But i tried it with \'\".$string2.\"\' and \'$string2\' etc....
Unfort. no dice.

Field is a VARCHAR of 16 of length.

Any other ideas?

THANKS!


I found it....

when i use this CHAR(\'$string2\') for every field, it works.
....


Weird.... Now your solution works... finally. THANKS!
I found out, that CHAR() and ASCII() returns the sum of char values.... logical...I had to remember that when i developed in C years ago...

It works!!!! Thanks for the help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users