PDA

View Full Version : PHP Update problem with "-" symbol



Morgenmuffel
07-02-2006, 05:28 PM
Hi all

A number is being returned as "454776-01" (which is correct) and when I echo the number out it echos out as "454776-01", BUT when i write it to the database it gets written in as "454776" everything after the "-" symbol is lost
and I can't work out how to prevent it losing the data
the field in the database is a varchar(50) so that shouldn't be a problem

If i can echo out the returned number, then i should be able to write it to the database shouldn't I?

$bob = $ti;
echo $bob.'<br>'; this echos out as 454776-01

mysql_query("update a_orders
set error_code = ".$ec.",
transaction_Id = ".$bob."
where order_Id = '".$merchant_ref."'
AND merchant_session = '".$ms."'");

Thanks

gibler
07-02-2006, 05:57 PM
Doesn't transaction_Id's value $bob need to be quoted as well just like you do in the ...where order_Id = '".$merchant_ref."' part?? Otherwise MySQL is thinking it is a number of sorts.

I'd just write code like:

$sql = "update a_orders
set error_code = ".$ec.",
transaction_Id = ".$bob."
where order_Id = '".$merchant_ref."'
AND merchant_session = '".$ms."'";

and echo that to what sql query that MySQL is getting.

You want to quote with a function like this (http://nz.php.net/manual/en/function.mysql-real-escape-string.php) . Or use PEAR DB abstraction layer or something.

Morgenmuffel
07-02-2006, 09:37 PM
Doesn't transaction_Id's value $bob need to be quoted as well just like you do in the ...where order_Id = '".$merchant_ref."' part?? Otherwise MySQL is thinking it is a number of sorts.


Exactly right

Thanks Gibler

this is the second time in as many days as i have missed the obvious,

thank god the school holidays finish tomorrow, i'll be able to work without bored kids, tv and the barbie website chattering on in one ear