Help with getting the array to populate the table

I’m trying to change the php file so that the data is inserted into the ‘videos_transactions’ table instead of the ‘u_paid_videos’ table. The ‘videos_transactions’ table has the structure of id, user_id, paid_id, video_id, amount, admin_com, time. I have commented-out the working array (u_paid_videos), and tried to substitute with the new one (videos_transactions), here’s the file code below. Any suggestions to try to get the new table to populate via the array, is appreciated.

<?php
ob_start();

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'];
 	}

	$db->where('name', 'rent_price');
	$db_cost = $db->getOne('config');
	$video_cost = (float)$db_cost->value;
	$count_video = count($id_array);
	$user_id = $user->id;
	$wallet = (float)str_replace(',', '', $user->wallet);
	$balance = (float)str_replace(',', '', $user->balance);
	$amount = 0;
	foreach ($id_array as $id) {
		$video_id = (int)PT_Secure($id);
		$video = $db->where('id', $id)->getOne(T_VIDEOS);
		$amount += $video->rent_price?$video->rent_price:$video_cost;
	}

	if( ($wallet >= $amount) OR ($balance + $wallet >= $amount) ) {
		$db->startTransaction();
		$inserted_records = 0;
		foreach ($id_array as $id){
			$video_id = (int)PT_Secure($id);
			$video = $db->where('id', $id)->getOne(T_VIDEOS);
			$video_cost_new = $video->rent_price?$video->rent_price:$video_cost;
			$up_amount = $video_cost_new *0.50;
			$site_add_amount = $video_cost_new *0.50;
			$time_start = microtime(true);

							// add data to paid 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
								//]);

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

etc...

Well, what is the error it is giving you? Did you make sure all the variables you are trying to insert have valid data that will fit into the new table? The error will tell you what is wrong if it is not working. Perhaps share the error message and if the error message reads “invalid video_id” then look to make sure $video_id has a value you expect.

Sounds like simple straight forward debugging here.

Where does $uploader_amount come from? I see you try to write it into the table, but I don’t see where you created it. But, as @Martyr2 said above, what is the error?

thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.