Jump to content

Update table with + and - values?


Breana

Recommended Posts

Ok, i have a form called save and it points to the same page with a ?task=save

and in the php i have, this code to grab it but i don't know how to load each value + or - from the info submited!

 

if($task == "save"){
$user_points - $_POST['$user_savings'];
$user_savings + $_POST['$user_savings'];
  $database->database_query("UPDATE se_users SET user_points='$user_points' WHERE user_id='".$user->user_info[user_id]."' LIMIT 1");
  $database->database_query("UPDATE se_users SET user_savings='$user_savings' WHERE user_id='".$user->user_info[user_id]."' LIMIT 1");
  header("Location: my_bank.php"); exit;
}

 

What am i missing to make it actualy change the values from what was submited?

Link to comment
https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/
Share on other sites

a single update is sufficient

 

$sql = "UPDATE se_users SET 
               user_points='$user_points', 
               user_savings = '$user_savings'
           WHERE user_id='{$user->user_info['user_id']}' LIMIT 1";

You need to do a select query and actually get the proper values! Or you can just do it directly in the update.  Here, do this:

 

if($task == "save"){

$savings = $_POST['$user_savings'];

 

  $database->database_query("UPDATE se_users SET user_points=user_points-$savings, user_savings=user_savings+$savings WHERE user_id='".$user->user_info[user_id]."' LIMIT 1");

 

  header("Location: my_bank.php"); exit;

}

I don't get i just tried your code nothing happened?

if($task == "save"){
$savings = $_POST['$user_savings'];

$database->database_query("UPDATE se_users SET user_points=user_points-$savings, user_savings=user_savings+$savings WHERE user_id='".$user->user_info[user_id]."' LIMIT 1");

  header("Location: my_bank.php"); exit;
}

 

But if i use this it changes!

if($task == "save"){
$user_points -= $_POST['user_savings'];
$user_savings += $_POST['user_savings'];
$database->database_query("UPDATE se_users SET user_points='$user_points' WHERE user_id='".$user->user_info[user_id]."' LIMIT 1");
$database->database_query("UPDATE se_users SET user_savings='$user_savings' WHERE user_id='".$user->user_info[user_id]."' LIMIT 1");
  header("Location: my_bank.php"); exit;
}

 

So what changes in the code to make it not work...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.