Chrisj Posted December 6, 2022 Share Posted December 6, 2022 (edited) Any ideas/suggestions as to why this may not be succeeding? $up_user = $db->where('id', $video->user_id)->getOne(T_USERS); $uploader_wallet = $up_user->$user->wallet; $upwallet = ($sell_video == 0 && $uploader_wallet >= 1 ? .5 : 0); $db->rawQuery("UPDATE ".T_USERS." SET `wallet` = `wallet`-'".$upwallet."' WHERE `id` = '".$video->user_id."'"); Success would be deducting .5 from the uploader's wallet account, when it has 1 or more, and when the sell price is zero. (The sell_price is located in the db video table and the wallet is located in the db users table.) I have tried echoing, but saw no display. I look forward to any helpful suggestions/guidance Edited December 6, 2022 by Chrisj Quote Link to comment https://forums.phpfreaks.com/topic/315616-any-idea-as-to-why-this-is-not-deducting/ Share on other sites More sharing options...
ginerjm Posted December 6, 2022 Share Posted December 6, 2022 Perhaps you could find a way to echo out the actual query that gets run? 1 Quote Link to comment https://forums.phpfreaks.com/topic/315616-any-idea-as-to-why-this-is-not-deducting/#findComment-1603283 Share on other sites More sharing options...
Psycho Posted December 6, 2022 Share Posted December 6, 2022 In addition to echoing out the query, you would want to check any variables in that part of the code. The construction of the ternary operator line looks odd. Typically I would put the conditions (especially when there are multiple) within parens. Although, that does seem to work in my install. I see that the $upwalle value is being put into quote marks in the query, which is not proper for a numerical value - same with the id value. Also, you are ALWAYS running the query even if you are not intending to change the value. You should only run the query if you are intending to make a change. Here is some very verbose debugging. I also made some minor tweaks to the code. What are your results when running this: echo "Get user for id: {$video->user_id}<br>"; $up_user = $db->where('id', $video->user_id)->getOne(T_USERS); echo "Get wallet amount for user: "; $uploader_wallet = $up_user->$user->wallet; echo "{$uploader_wallet}<br>"; echo "Calculate change to wallet: "; $upwallet = ($sell_video == 0 && $uploader_wallet >= 1) ? .5 : 0; echo "{$upwallet}<br>"; echo "Check if upwallet value is not zero: "; if($upwallet > 0) { echo "True - run update query<br>"; echo "Construct query: "; $query = "UPDATE ".T_USERS." SET `wallet` = (`wallet` - {$upwallet}) WHERE `id` = {$video->user_id}"; echo "{$query}<br>"; echo "Run query: "; $db->rawQuery($query); echo "Complete"; } else { echo "False - do not run update query<br>"; } 1 Quote Link to comment https://forums.phpfreaks.com/topic/315616-any-idea-as-to-why-this-is-not-deducting/#findComment-1603298 Share on other sites More sharing options...
mac_gyver Posted December 6, 2022 Share Posted December 6, 2022 14 hours ago, Chrisj said: I have tried echoing, but saw no display. no display/a blank page from a php script is usually due to fatal parse errors or fatal runtime errors. 14 hours ago, Chrisj said: $up_user->$user->wallet; this is throwing a fatal error, since $up_user is an object, $user doesn't exist, and you are trying to get the ->wallet property of that object. the likely (since we don't know the backstory about what you are doing) syntax should be $uploader_wallet = $up_user->wallet; do you have php's error_reporting set to E_ALL and display_errors set to ON, in the php.ini on your system so that php will help you by reporting and displaying ALL the errors it detects? you will save a ton of time. 1 Quote Link to comment https://forums.phpfreaks.com/topic/315616-any-idea-as-to-why-this-is-not-deducting/#findComment-1603299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.