Jump to content

Update query not working


kaosjon

Recommended Posts

Hi, i am currently designing a new website and am testing a few different compnents of it. One part gathers two variables of the url using the GET method and selects the relevant data from the database. It then performs an UPDATE of a field called balance before INSERTING a new record. Everything works and gets inserted except for the UPDATE.

 

Here is the code

 

<?php
include ("connect.php");

$id = "";
$offerid = "";

$id = $_GET['user_id'];
$offerid = $_GET['offer_id'];

$sql_user = mysql_query("SELECT * FROM user_info WHERE id = $id");

$sql_offer = mysql_query("SELECT * FROM offers WHERE offerid = $offerid");

$balance += $payout;

mysql_query("UPDATE user_info SET balance = $balance WHERE id = $id");

mysql_query ("INSERT INTO offer_credited (id, offerid, date_credited, payout_to_user) VALUES ('$id', '$offerid', CURDATE(), '$payout')") or die(mysql_error());

echo "Your Offer has been recorded and Updated"
?>

 

The balance field is a float that i want to increase by the amount of the payout variable which is from the offers table. However, the balance never gets updated and remains at 0.

 

Any ideas what it could be, i am thinking it is something to do with,

 

$balance += $payout;

 

But i can't think of what else to do.

 

Hopefully this isn't too confusing.

 

Thanks for the help

 

Link to comment
Share on other sites

Is $balance assigned a value at some point prior to $balance += $payout?

$payout is likely undefined, making $balance empty, therefore the query fails.

If $balance is supposed to come from one of the previous queries, note that all you have after mysql_query() is a result resource unless you do something with that resource using one of the mysql_fetch_[row/assoc/array] functions.

 

$array = mysql_fetch_assoc($sql_offer);
$balance = $array['payout'];

Link to comment
Share on other sites

Is $balance assigned a value at some point prior to $balance += $payout?

$payout is likely undefined, making $balance empty, therefore the query fails.

If $balance is supposed to come from one of the previous queries, note that all you have after mysql_query() is a result resource unless you do something with that resource using one of the mysql_fetch_[row/assoc/array] functions.

 

$array = mysql_fetch_assoc($sql_offer);
$balance = $array['payout'];

 

Hi, thanks for the reply, i done what you said and it seems to work slightly, it adds the payout to the balance and updates it, but when i tried it again, it should add the payout to the balance but it doesn't. In other words the first time i tried it the balance went from 0 to 1 because the payout is 1, however the second time i tried it the balance remained at 1 and did not change. It should have gone to 2. I am not sure what is not working in the code, any ideas?

 

Thanks for the help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.