Help with reflecting accurate price

the php web video script that I’m trying to modify allows Users to purchase videos successfully, however, the video price that is reflected in the db (‘u_paid_videos’) table (where transaction info is stored) appears to show the default video price (video_play_price from the ‘config’ db table) every time, instead of the accurate video price. I’m not sure if this code needs to be tweaked so that the actual price will show in the ‘video_play_price’ column (in ‘u_paid_videos’ table):

// 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) ) {


		$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);

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

			$uploader_amount = $video_cost_new *0.50;

			// add data to paid table
			$insert_buy = $db->insert('u_paid_videos', [
				'id_user' => $user_id,
				'id_video' => $video_id,
				'session_key' => $_SESSION['session_key'],
				'video_play_price' => (string)$video_cost,
				'video_title' => $video->title, 
				'user_id_uploaded' => $video->user_id, 
				'earned_amount' => $uploader_amount


any suggestions are welcomed

Yes, it’s doing exactly what you told it to do.

Thanks for your reply.
As I didn’t write that code, I’m not sure how to remedy that so as to have the actual price show in the ‘video_play_price’ column (in ‘u_paid_videos’ table), instead of the default price; which I’m guessing is the videos_cost_new?

Any help is appreciated

I dont know what value you want to store there.

I’m not writing your application. That’s your responsibility to know.

1 Like