View Full Version : PHP update help.

02-28-2010, 09:48 PM
I'm looking for some help with my site.

This is the code I have so far.

require ("../connect.php");

<div id="content" align="center">

if($_SESSION['status'] != 2){
if($_SESSION['status'] == 2){
$offerUid = mysql_real_escape_string($_GET['coid']);

$result = mysql_query("SELECT * FROM pending WHERE id='$offerUid'");
$data = mysql_fetch_array($result);
$value = $data['amount'];
$offer = $data['offerID'];
$userid = $data['userID'];
$user2 = $data['username'];

$bresult = mysql_query("SELECT * FROM users WHERE id='$userid'");
$getui = mysql_fetch_array($bresult);
$balance = $getui['complete'];
$pending = $getui['pending'];
$newbalance = $balance + $value;
$newpending = $pending - $value;

mysql_query("UPDATE users SET complete='$newbalance' WHERE id='$userid'");
mysql_query("UPDATE pending SET status='1' WHERE id='$offerUid'");
mysql_query("UPDATE users SET pending='$newpending' WHERE id='$userid'");
echo "The offer has been confirmed and the user has been credited.";




This code takes the value of a field in the database and adds it to a field in the table 'users' called complete. It then take away that value from a field called 'pending'.

I would like it so that when the field called complete in 'users' has the value equal or the same as 1.00 it will check 'users' for their user id in a field called 'refer' and add a 1 to the field called 'complete referrals'.

Eg. If a user called 'Bob' refers a user called 'Alan', it will update the field called refer in 'Alans' table with 'Bobs' user id. If 'Alan' has the value equal or the same as 1.00 in a field called complete, it will then update a field called completereferrals in 'Bobs' table with the number 1.

Can anyone help me with this please?


03-01-2010, 07:13 AM
C'mon, try to write this code, it is not that hard :)
We will help you with errors , if you encounter any.