Breana Posted May 12, 2008 Share Posted May 12, 2008 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 More sharing options...
fred123 Posted May 12, 2008 Share Posted May 12, 2008 I think you want to use += and -= as in... $user_points -= $_POST['user_savings']; $user_savings += $_POST['user_savings']; Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538623 Share on other sites More sharing options...
Breana Posted May 12, 2008 Author Share Posted May 12, 2008 Hi just call me stupid :0 Lol it works now man i am a nube when it comes to sql... SOLVED!! Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538624 Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 It actually has nothing to with SQL at all. =P You weren't assigning the variables correcting. Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538626 Share on other sites More sharing options...
Barand Posted May 12, 2008 Share Posted May 12, 2008 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"; Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538631 Share on other sites More sharing options...
Breana Posted May 12, 2008 Author Share Posted May 12, 2008 I have an issue with it, it works but sets the over all value as submited by the form... I had 4,500 points i clicked save 55 points and it set my points to -55 why? And save to 55 i don't want it to remove the old value... Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538647 Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 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; } Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538648 Share on other sites More sharing options...
Breana Posted May 12, 2008 Author Share Posted May 12, 2008 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... Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538649 Share on other sites More sharing options...
Breana Posted May 12, 2008 Author Share Posted May 12, 2008 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... Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538652 Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 -0? O_O Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538654 Share on other sites More sharing options...
Breana Posted May 12, 2008 Author Share Posted May 12, 2008 Oh sorry i mean in the points table, i want it to say Error you have no points to save. If the value in there is less than 0 "you know" nothing to take so it don't go into the -0 values... Link to comment https://forums.phpfreaks.com/topic/105194-update-table-with-and-values/#findComment-538668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.