Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP resolved--

chrisj

Bronze Coder
In the php file this works successfully:

PHP:
        // add data to table
        $insert_buy = $db->insert('u_paid_videos', [
        'id_user' => $user_id,
        'video_play_price' => (string)$video_cost_new,
        'id_video' => $video_id,
        'user_id_uploaded' => $video->user_id,
        'video_title' => $video->title,
        'earned_amount' => $up_amount,
        'time' => $time_start,
        'short_id' => $video->short_id,
        'session_key' => $_SESSION['session_key']
        ]);

I’d like to add this data to a different table that has these columns:
id, user_id, paid_id, video_id, amount, admin_com, time

This replacement now works successfully:
PHP:
// add data to table
$insert_buy = $db->insert(‘videos_transactions’, [
‘paid_id’ => $user_id,
‘video_id’ => $video_id,
//‘user_id’ => $user_id_uploaded,
‘amount’ => $video_cost_new,
‘admin_com’ => $uploader_amount,
‘time’ => $time_start
]);

However, I can’t seem to figure out how to have the (video) uploader’s id to populate the ‘videos_transactions’ table’s ‘user_id’ column.
Here’s the code up to the array:

PHP:
<?php
ob_start();
error_reporting(-1); // set maximum errors
error_reporting(E_ALL);
ini_set(‘display_errors’ , ‘true’);

if (IS_LOGGED == false) {
    $data = array('status' => 400, 'error' => 'Not logged in');
    echo json_encode($data);
    exit();
}

if (!empty($_POST['id'])) {

    if (!is_array($_POST['id'])) {
        $id_array[] = $_POST['id'];
    } else {
        $id_array = $_POST['id'];
     }

    // get cost video
    // get the default video price, to use if there is no per video play price
    $db->where('name', 'video_play_price');
    $db_cost = $db->getOne('config');
    $video_cost = (float)$db_cost->value;

    // the number of submitted videos - used to determine if all records were inserted
    $count_video = count($id_array);
    $user_id = $user->id;

    $wallet = (float)str_replace(',', '', $user->wallet);
    $balance = (float)str_replace(',', '', $user->balance);

    // add up the video prices
    $amount = 0;
    foreach ($id_array as $id) {

        $video_id = (int)PT_Secure($id);

        // get video data
        $video = $db->where('id', $id)->getOne(T_VIDEOS);
        // add the video play price if any, or the default price
        $amount += $video->video_play_price?$video->video_play_price:$video_cost;
    }

    // determine if the user has enough credits
    if( ($wallet >= $amount) OR ($balance + $wallet >= $amount) ) {

        $db->startTransaction();

        $inserted_records = 0;
        foreach ($id_array as $id){

            $video_id = (int)PT_Secure($id);

            // get video data
            $video = $db->where('id', $id)->getOne(T_VIDEOS);
            //$video = $db->where('short_id', $short_id)->getOne(T_VIDEOS);

            // use the video play price if any, or the default price
            $video_cost_new = $video->video_play_price?$video->video_play_price:$video_cost;

            // credit the user 50% of the video cost
            $uploader_amount = $video_cost_new *0.50;

            $time_start = microtime(true);
            //$time_start = date('Y-m-d H:i:s');

            // add data to paid table
            $insert_buy = $db->insert('videos_transactions', [
            'paid_id' => $user_id,
            'video_id' => $video_id,
            //'user_id' => $user_id_uploaded,
            'amount' => $video_cost_new,
            'admin_com' => $uploader_amount,
            'time' => $time_start
             ]);

any help with this is appreciated.
 
Hi there,

Even though it's resolved, please do not remove the content from the original posting. This is part of the Code of Conduct because it helps others who may be encountering a similar issue discover your thread and help them resolve their issue. If you could share the solution and mark it as the solution, then that would be great.

Nice seeing you on Code Forum :)
 

New Threads

Buy us a coffee!

Back
Top Bottom