Topic: Could anyone tell me how to...? (Read 1528 times)
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« on: Jan 24, 2007, 01:36:10 AM »
Hi guys, first of all, a brief and as clear as possible as i could explanation of what i want to do:
This is for an Account Balance script. When a new customer signs up, the customer will have into a cell of my SQL his balance, let's say: 1,200$. Obviously into the database, for every user row I have the Balance field with it's respective and particular balance.
Now here is where I get stuck. Let's say that the customer has to pay 100$ per month in order to clear the balance when the 1 year (or anything) period it's over.
So, customer goes every month at the bank, customer sends his payment to our bank account, customer logs into our website and sends the payment confirmation with it's amount via a web form. so, that form sends a $_GET parameter to another script that will UPDATE how much balance is left into the account in our database.
My plain question is: How to rest a particular amount to a MySQL query, and then update the amount in the database?
Regards everyone!
« Last Edit: Jan 24, 2007, 01:38:56 AM by eliezer »
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6487
39754 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Jan 24, 2007, 09:54:30 AM »
Is this problem that kind of simple or do I not understand?
It sounds like a normal update statement to me:
Code:
$sql = sprintf('UPDATE table SET amount = %f', $_GET['conf_amount'])
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #2 on: Jan 24, 2007, 11:15:06 AM »
So, if the 'amount' on 'table' is 1200 and i run that query with a $_GET['conf_amount']) value of 120, will that update the 'amount' to 1080?
p.s. could you explain me the %f thingie? to be honest, never heard of sprintf() and I do not understand the %f thing. I guess %f takes the value of $_GET['conf_amount']) to work it into the query. huh?
« Last Edit: Jan 24, 2007, 11:19:51 AM by eliezer »
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6487
39754 credits Members referred : 374
It's time to use PHP5!
« Reply #3 on: Jan 24, 2007, 11:28:26 AM »
check the manual for sprintf
to get the the right amount you need to calculate the value:
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #7 on: Jan 24, 2007, 03:47:45 PM »
Thanks once again for the support guys. I see what Nikolas is telling me, it could work. But, just to make sure, if I use Olaf's example I would be able to handle cents, right?
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6487
39754 credits Members referred : 374
Thanks once again for the support guys. I see what Nikolas is telling me, it could work. But, just to make sure, if I use Olaf's example I would be able to handle cents, right?
Thanks once again for the support guys. I see what Nikolas is telling me, it could work. But, just to make sure, if I use Olaf's example I would be able to handle cents, right?
yes, if your database table column can handle it
varchar Shall support it, shouldn't it? Because it has no Integral (sp Integer?) value, right?
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #10 on: Jan 25, 2007, 05:07:53 AM »
Would this be right? specially the mysql_query line. Sorry, Im a noob. Im going to try the code and try to find the error wich Im sure will be there. But anyway, if you got any advise my ears are wide open.
Thanks once again for the support guys. I see what Nikolas is telling me, it could work. But, just to make sure, if I use Olaf's example I would be able to handle cents, right?
yes, if your database table column can handle it
varchar Shall support it, shouldn't it? Because it has no Integral (sp Integer?) value, right?
varchar can simply hold a decimal number such as "22.56", but can not use it for calculations after it is stored in the database unless you modify the datatype to handle decimals.. otherwise you could use varchar, if you simply want to store that number and update it from time to time
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6487
39754 credits Members referred : 374
It's time to use PHP5!
« Reply #12 on: Jan 25, 2007, 09:10:29 AM »
Quote
varchar Shall support it, shouldn't it? Because it has no Integral (sp Integer?) value, right?
varchar is a text type, of course you can canvert each string to a integer/float, but for better performance you should use a decimal or integer column type.
btw. in your last code snipped, where is the sql statement?
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #13 on: Jan 25, 2007, 11:46:02 AM »
Hey guys, I got a little bit confused with the sprintf thing. I cannot get it to work so instead I chose Nicolas option and it did work BUT when I add a WHERE statetement to the query, it quits working. If I remove the WHERE statement it updates the whole CUSTOMERS table. Here's my code:
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #15 on: Jan 25, 2007, 12:31:01 PM »
Replaced it, nothing happenned. Not even error message. Here's the script in action, right now it's exactly the same code as above with the lined you asked to be replaced, replaced.
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #17 on: Jan 25, 2007, 03:37:21 PM »
It just doesn't change and store the new amount. It shows the succesfull message inside the loop ( {...} ) but the update through the query it just doesn't seem to work even though it seems to be properly stated.
Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #18 on: Jan 25, 2007, 03:41:44 PM »
try
Code:
echo "Customer id: $id_customer";
just before the update statement. That should show you the customer ID on screen so you can verify that it is filled correctly