Jump to content

Recommended Posts

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 by Chrisj

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>";
}

 

  • Like 1
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.

  • Like 1
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.