Jump to content

Update problem with numbers and text


hessie

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.