Mysql Update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
geryatric
Forum Newbie
Posts: 2
Joined: Sat Oct 17, 2009 4:06 am

Mysql Update

Post by geryatric »

I am developing a script which will take a number from the url divide it by the number of members in a table add it with the balance already on the table and save the total. Then update the table with the new total.
All is working fine only the table wont update, could some one advise me on the update query.

Code: Select all

if(isset($_POST['$lotto_id'])){$lotto_id = $_POST['$lotto_id'];}
if(isset($_POST['$income'])){$income = $_POST['$income'];}
 
$query = "SELECT lotto_id, balance FROM lotto_member WHERE lotto_id =$lotto_id";
 
$result = mysql_query($query) or die;
$num_res = mysql_num_rows($result);
$num_rows = mysql_num_rows($result);
for ($i=0; $i<$num_res; $i++){
$row = mysql_fetch_array($result);
 
// existing Balance in table
$balance = $row["balance"];
 
// Divide the new amount by the number of members
$split = $income / $num_rows;
 
// add the two together
$member_total = $split + $balance ;
 
// test it
echo "$member_total <br>";
}
// update the DB
$query = "UPDATE lotto_member SET balance='$member_total' WHERE lotto_id =$lotto_id";
Thank you
Last edited by geryatric on Sat Oct 17, 2009 1:32 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Mysql Update

Post by requinix »

Can't help but notice that the UPDATE is using $balance as the new value...

Code: Select all

// add the two together
$member_total = $split + $balance ;
geryatric
Forum Newbie
Posts: 2
Joined: Sat Oct 17, 2009 4:06 am

Re: Mysql Update

Post by geryatric »

Thanks for the reply tasairis
That was a typo and I just corrected it .
having played around with it during the the day I think the problem is in the
mysql_fetch_array($result);
any thoughts ?
Post Reply