Topic: Could anyone tell me how to...? (Read 2971 times)
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #20 on: Jan 25, 2007, 02:54:22 pm »
Alright, it happened that I translated the file to english to post it here, but it seems that I forgot to translate back to spanish a variable... my bad. Anyway, the query is still not working. S:
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #22 on: Jan 25, 2007, 03:17:57 pm »
That's alright now. I realized that if I exchange the '," marks, so the query looks like this:
Code:
$sql="UPDATE clientes SET saldo = saldo - " . (int)$_GET['monto'] . " WHERE
id_cliente=" . $id_cliente . "";
then I get this error: Unknown column 'eliezer.com' in 'where clause'
I don't know why it's taking the value as a column it has the equal mark and everything.
« Last Edit: Jan 25, 2007, 03:19:37 pm by eliezer »
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #23 on: Jan 25, 2007, 03:23:32 pm »
because you have to place strings into SINGLE quotes:
$sql="UPDATE clientes SET saldo = saldo - " . (int)$_GET['monto'] . " WHERE
id_cliente= ' " . $id_cliente . " ' "; (remove the spaces and maybe you should use LIKE and not =)
and of course it is time start with some beginners tutorials, your problems are really mistakes made by newbies
« Last Edit: Jan 25, 2007, 03:26:06 pm by olaf »
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #24 on: Jan 25, 2007, 03:29:23 pm »
I love you. ( : It worked!
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #25 on: Jan 25, 2007, 03:29:34 pm »
here is also the sprintf version (and tell me what is better to read)
Code:
<?php $sql= sprintf("UPDATE clientes SET saldo = saldo - %d WHERE id_cliente = '%s'", $_GET['monto'], $id_cliente);
btw. you need to validate the value $id_cliente to prevent SQL injections
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #26 on: Jan 25, 2007, 03:45:29 pm »
For some reason, if I use sprintf on 'saldo' column when I register a payment of 100.00 its gets off 200.00 from the balance. If I input 50.00 it gets 100.00 off, if I input 150.50 it gets 200 off. It seems like it's taking the total to the closer integer.
MySQL 'saldo' column properties..
Code:
`saldo` DECIMAL(10,2) NOT NULL,
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #27 on: Jan 25, 2007, 03:47:48 pm »
in this case you need this one:
<?php $sql= sprintf("UPDATE clientes SET saldo = saldo - %f WHERE id_cliente = '%s'", $_GET['monto'], $id_cliente);
note the %f
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #28 on: Jan 25, 2007, 03:51:28 pm »
I would like to know what are those letters about. I guess they define arguments or something... anyway... last query does take the decimals exactly, BUT every amount I input it gets doubled.
( any amount ) * ( 2 )
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
I would like to know what are those letters about. I guess they define arguments or something... anyway... last query does take the decimals exactly, BUT every amount I input it gets doubled.