MYSQL transfer same or less than balance [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a form where 2 users can transfer funds to each other.
Here is my code
$accountfrom=$_POST[accountfrom];
$accountto=$_POST[accountto];
$amount=$_POST[amount];
$result = mysql_query("UPDATE member
SET balance = IF(personID = $accountfrom, balance-$amount, balance+$amount)
WHERE personID IN ($accountfrom, $accountto)")
or die(mysql_error());
However if the user only has a balance of £10, this allows them to still trasfer more than they have available. Is there a way to stop this?
(the balance is stored in field named balance)

You need to query for available funds first. Then you check against the required funds and decide to update or not.

Related

Retreiving a record from the database WHERE you just need the year/month/day to match [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my database I have a entry_date that is set as a DATETIME type, how do I go about querying the database for a specific day? For example if I have a record with 2013-12-27 16:14:10
and I only really care that I'm getting the record where the 2013-12-27 matches.
Assuming MySQL, use DATE():
Extracts the date part of the date or datetime expression.
SELECT *
FROM tablename
WHERE DATE(datecol) = '2013-12-27'

rotating list per refreshing page [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Lets say there are three rows of information that loads on a site, and on the site, you only want 1 of the 3 rows to load each time the page gets refreshed, so it probably should be sorted by random or something better. what is the best code for this?
Go for array_rand()
<?php
$arr=array("Offer 1","Offer 2","Offer 3");
$val=array_rand($arr,1);
echo $arr[$val];

Query information about my app's user in twitter [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to query information about my app's user Info (name, id...)
In twitter (PHP).
What I want to know how I can reuse the token credentials of user???
I have done that but with my Twitter session. It means I must login with my twitter account, after that I can query information about my app's user (That's not correct!!!!!).
Please read this, this will be useful for your query :-
http://mikerogers.io/2013/02/25/how-use-twitter-oauth-1-1-javascriptjquery.html

Check Read and unread Message [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to conditionally style user-to-user messages on my site based on the following:
If the user has not yet accessed the message, it remains bold ("unread").
If the user clicks the link and accesses it, it goes from bold to unbold ("read")
(reference: this is how many email inboxes work)
Question: How would I check if the user has clicked on the link to view their new message, or if they have not? As in, how would I store this information and indicate that it has been "read"?
Try adding a column to your messages' table (for example read) and set this column to 1 when the user has read his message?

PHP Mysql insert mathematical formula into database [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to create a simple PHP web system to “view”, “add”, “edit” and “delete” loan applications. The problem is during add new loan records to the system because i need to calculate formula for calculating "home loan" installment amount
The formula :
amount and duration is fetch during user fill up the form
Question : How i do mathematical operation to calculate installment amount from what user fill in the form to insert in mysql database? Thanks
Hope this helps.
<?php
$interest=0.5;
$amt=$_POST['amount'];
$duration=$_POST['duration']; // duration is in months
$intamt=pow((1+$interest),$duration);
$intamt2=pow((1+$interest),($duration-1));
$installment=($amt*0.5*$intamt)/$intamt2;
echo $installment;
?>
Check the working example here(http://codepad.org/Fw3wbsUP)

Categories