Jump to content

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

Never mind i had to remove the $ in the post part smarty don't like it i guess it works now thanks!!

I tested it 6 times with different values and it does  increase on save and decreases on points.

 

What is a good way to keep it from going into -0 on points...

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.