Help with updating minimum price

The php web video script that I’m using calculates the cost of the video. All uploaded videos are priced at what the Admin has set in admin panel, (but after uploading the uploader can change the price). All that works successfully.

I’m trying to add the ability where the default price set by Admin is the Minimum Price, so uploaders can’t price a video below that (currently an uploader can change to any price - from his logged-in account).

I have gotten so far as to have the Minimum Price now display - as the Purchase Price on the listed videos page (when the User tries to set a lower price than Minimum Price), but, the actual purchase reflects the uploaders’ lower price, not the displayed Minimum Price.

Whenever a User/Uploader changes the price in his account >edit-video form, the number reflected in videos (table) > video_play_price (column) is updated.
But, it appears that the minimum price is not being updated in videos (table)> video_play_price (column), (because it remains at the less-than the minimum price).
So, I need help with updating the Minimum price - in the video_play_price column.

The solution needed might be in this part of code in the
…/layout/edit-video/content.html file:

<div class="form-group">
<label class="col-md-12" for="cost">{{LANG up_video_price}}</label>
<div class="col-md-12">
<input id="cost" input type="number" name="video_play_price" class="form-control input-md" value="{{video_play_price_user}}">
</div>
</div>

</div>

Or in the…/sources/edit-video/content.php file:

<?php
if (IS_LOGGED == false) {
    header("Location: " . PT_Link('login'));
    exit();
}
if (empty($_GET['id'])) {
    header("Location: " . PT_Link('login'));
    exit();
}
$id    = PT_Secure($_GET['id']);
$video = $db->where('id', $id)->getOne(T_VIDEOS);
if (empty($video)) {
    header("Location: " . PT_Link('login'));
    exit();
}
if (!PT_IsAdmin()) {
    if (empty($db->where('id', $id)->where('user_id', $user->id)->getValue(T_VIDEOS, 'count(*)'))) {
        header("Location: " . PT_Link('login'));
        exit();
    }
}
$video           = PT_GetVideoByID($video, 0, 0, 0);
$pt->video       = $video;
$pt->page        = 'edit-video';
$pt->title       = $lang->edit_video . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;

$min_price=$config[‘video_play_price’];
$temp_price = $videos[‘video_play_price’];
if ($temp_price<$min_price) { $temp_price = $min_price;}


$pt->content     = PT_LoadPage('edit-video/content', array(
    'ID' => $video->id,
    'USER_DATA' => $video->owner,
    'THUMBNAIL' => $video->thumbnail,
    'URL' => $video->url,
    'TITLE' => $video->title,
    'DESC' => br2nl($video->edit_description),
    'DESC_2' => $video->markup_description,
    'VIEWS' => $video->views,
    'TIME' => $video->time_ago,
    'TAGS' => $video->tags,
	   //'video_play_price' => $u_paid_videos->video_play_price,
	    //'video_play_price_user' => number_format($video->video_play_price?$video->video_play_price:$config['video_play_price'])
	    'video_play_price_user' => number_format( $video->video_play_price < $config['video_play_price'] ? $config['video_play_price'] : $video->video_play_price)

));

Or in the this section of the …/ajax/edit-video/content.php file:

$video_play_price = floatval(PT_Secure($_POST['video_play_price']));
		if ( $video_play_price < $config[‘video_play_price’] ) {
		   $video_play_price = $config['video_play_price'];
}


		$data_update = array(
	        'title' => PT_Secure($_POST['title']),
	        'description' => PT_Secure($_POST['description']),
	        'tags' => PT_Secure($_POST['tags']),
	        'category_id' => $category_id,
	        'featured' => $featured,
	        'thumbnail' => $thumbnail,
	        'privacy' => $video_privacy,
	        'age_restriction' => $age_restriction,
	        'video_play_price' => $video_play_price,

	    );
,,,,,

Any suggestions will be appreciated.

Is this the same question as your previous topic?

It sounds very much like the same problem.

Thanks for your reply.
It is similar, but I have added code that creates the minimum price, this posting is specifically about getting help with updating to the db. Can you provide a solution?

Didn’t you try anything by yourself to find a solution? It’s pretty clear that it has nothing to do with the HTML file, as HTML is not capable of writing into your database and the file lays in a directory named “layout”. It’s unclear where any SQL update should run as you did not provide any related code, it’s just a guess that it has anything to do with $data_update. And there’s already code that should handle the price, but you didn’t give any example of incoming data. Also you should use adequate quotes instead of mixing them - there’s an explicit warning on that! (Warning: Use of undefined constant ‘video_play_price’). After that you can just var_dump whatever in $data_update is.

2 Likes

FYI

if ($temp_price<$min_price) { $temp_price = $min_price;}

can be written as

$temp_price = min($min_price, $temp_price);

which a lot easier to read (imho)

Also, please try to find a code style and stick to it. The indentation in that code is all over the place :confused:

Compare:

$video_play_price = floatval(PT_Secure($_POST['video_play_price']));
		if ( $video_play_price < $config[‘video_play_price’] ) {
		   $video_play_price = $config['video_play_price'];
}


		$data_update = array(
	        'title' => PT_Secure($_POST['title']),
	        'description' => PT_Secure($_POST['description']),
	        'tags' => PT_Secure($_POST['tags']),
	        'category_id' => $category_id,
	        'featured' => $featured,
	        'thumbnail' => $thumbnail,
	        'privacy' => $video_privacy,
	        'age_restriction' => $age_restriction,
	        'video_play_price' => $video_play_price,

	    );

versus

$video_play_price = min(
    floatval(PT_Secure($_POST['video_play_price']))
    $config['video_play_price']
);

$data_update = array(
    'title' => PT_Secure($_POST['title']),
    'description' => PT_Secure($_POST['description']),
    'tags' => PT_Secure($_POST['tags']),
    'category_id' => $category_id,
    'featured' => $featured,
    'thumbnail' => $thumbnail,
    'privacy' => $video_privacy,
    'age_restriction' => $age_restriction,
    'video_play_price' => $video_play_price,
);
2 Likes

I’d agree, but shouldn’t it be max() rather than min() in this case? The OP doesn’t want to allow a price lower than $min_price to be stored.

2 Likes

Indeed, it should be max instead of min!

Thanks for your replies.
I had tried many thing before posting, without success.
Based upon the replies, I have corrected the adequate quotes.
Also, attempted to add var_dump ($data_update) like so (but no output):

		$data_update = array(
	        'title' => PT_Secure($_POST['title']),
	        'description' => PT_Secure($_POST['description']),
	        'tags' => PT_Secure($_POST['tags']),
	        'category_id' => $category_id,
	        'featured' => $featured,
	        'thumbnail' => $thumbnail,
	        'privacy' => $video_privacy,
	        'age_restriction' => $age_restriction,
	        'video_play_price' => $video_play_price,
			var_dump($data_update),
	    );

In regard to “did not provide any related code”, here’s the entire file code:

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


if (empty($_POST['title']) || empty($_POST['description']) || empty($_POST['tags']) || empty($_POST['video-id']) || empty($_POST['video_play_price'])) {
    $error = $lang->please_check_details;
}

if (empty($error)) {
    $id = PT_Secure($_POST['video-id']);
    $video = $db->where('id', $id)->getOne(T_VIDEOS);
    $can_update = false;
    if (PT_IsAdmin() == false) {
    	if ($db->where('user_id', $user->id)->where('id', $id)->getValue(T_VIDEOS, 'count(*)') > 0) {
    		$can_update = true;
    	}
    } else {
    	$can_update = true;
    }
    if ($can_update == true && !empty($video)) {
    	$video = PT_GetVideoByID($video, 0, 0, 0);
    	$thumbnail = $video->org_thumbnail;
    	if (!empty($_FILES['thumbnail']['tmp_name'])) {
	        $file_info   = array(
	            'file' => $_FILES['thumbnail']['tmp_name'],
	            'size' => $_FILES['thumbnail']['size'],
	            'name' => $_FILES['thumbnail']['name'],
	            'type' => $_FILES['thumbnail']['type'],
	            'allowed' => 'jpg,png,jpeg,gif',
	            'crop' => array(
	                'width' => 1076,
	                'height' => 604
	            )
	        );
	        $file_upload = PT_ShareFile($file_info);
	        if (!empty($file_upload['filename'])) {
	            $thumbnail = PT_Secure($file_upload['filename']);
	        }
	    }
	    $category_id = 0;
	    if (!empty($_POST['category_id'])) {
	        if (in_array($_POST['category_id'], array_keys($categories))) {
	            $category_id = PT_Secure($_POST['category_id']);
	        }
	    }
	    $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
	    $i          = 0;
	    preg_match_all($link_regex, PT_Secure($_POST['description']), $matches);
	    foreach ($matches[0] as $match) {
	        $match_url           = strip_tags($match);
	        $syntax              = '[a]' . urlencode($match_url) . '[/a]';
	        $_POST['description'] = str_replace($match, $syntax, $_POST['description']);
	    }
	    $featured = $video->featured;
	    if (isset($_POST['featured']) && PT_IsAdmin()) {
	    	$featured = PT_Secure($_POST['featured']);
	    }

	    $video_privacy = 0;
	    if (!empty($_POST['privacy'])) {
	        if (in_array($_POST['privacy'], array(0, 1, 2))) {
	            $video_privacy = PT_Secure($_POST['privacy']);
	        }
	    }
	    $age_restriction = 1;
        if (!empty($_POST['age_restriction'])) {
            if (in_array($_POST['age_restriction'], array(1, 2))) {
                $age_restriction = PT_Secure($_POST['age_restriction']);
            }
        }

		$video_play_price = floatval(PT_Secure($_POST['video_play_price']));
		if ( $video_play_price < $config[‘video_play_price’] ) {
		   $video_play_price = $config['video_play_price'];
}


		$data_update = array(
	        'title' => PT_Secure($_POST['title']),
	        'description' => PT_Secure($_POST['description']),
	        'tags' => PT_Secure($_POST['tags']),
	        'category_id' => $category_id,
	        'featured' => $featured,
	        'thumbnail' => $thumbnail,
	        'privacy' => $video_privacy,
	        'age_restriction' => $age_restriction,
	        'video_play_price' => $video_play_price,
	    );



	    $update  = $db->where('id', $id)->update(T_VIDEOS, $data_update);
	    if ($update) {
	        $data = array(
	            'status' => 200,
	            'message' => $success_icon . $lang->video_saved
	        );
	    }
    }
} else {
    $data = array(
        'status' => 400,
        'message' => $error_icon . $error
    );
}
?>

Also, changed this, as suggested, but still the same, no update:

$min_price=$config['video_play_price'];
$temp_price = $videos['video_play_price'];
$temp_price = max($min_price, $temp_price);
//if ($temp_price<$min_price) { $temp_price = $min_price;}

Any additional help will be appreciated.

It seems like I have seen this same topic pop up several times now. It also seems like you are just randomly throwing darts at the wall and crossing your fingers that things work. Placing var_dump() in random areas of code and crossing your finders you get there and debug is no way to debug larger code bases and applications. It is no surprise you are having a very difficult time navigating this code. I would HIGHLY recommend installing xdebug and using smart debugging. Once enabled smart debugging will allow you to debug code line by line in real time eliminating the need to clutter up code with dump statements. Leveraging MODERN debugging tools/workflows EFFICIENTLY is an ABSOLUTELY necessary skill for a TRUE professional engineer. There is a good reason real time debugging is baked into many modern languages like JavaScript, C#/.NET, etc.

https://xdebug.org/

1 Like

You can’t put it inside the array declaration. Put it after the close-bracket, and report back on what it displays.

		$data_update = array(
	        'title' => PT_Secure($_POST['title']),
	        'description' => PT_Secure($_POST['description']),
	        'tags' => PT_Secure($_POST['tags']),
	        'category_id' => $category_id,
	        'featured' => $featured,
	        'thumbnail' => $thumbnail,
	        'privacy' => $video_privacy,
	        'age_restriction' => $age_restriction,
	        'video_play_price' => $video_play_price,
	    );
	var_dump($data_update);

Do you have a column called video_play_price in your data table?

This code

$min_price=$config['video_play_price'];
$temp_price = $videos['video_play_price'];
$temp_price = max($min_price, $temp_price);

looks better now, but in the code you showed earlier I can’t see anywhere that you actually use $temp_price after you’ve gone to the trouble of calculating it. And, as I asked in the other thread you started on this same subject, where does the $videos array come from? I see one called $video where you read in from the database, but I don’t see one called $videos. Irrelevant as you don’t seem to use the price you calculate, I guess.

In your latest code:

		$video_play_price = floatval(PT_Secure($_POST['video_play_price']));
		if ( $video_play_price < $config[‘video_play_price’] ) {
		   $video_play_price = $config['video_play_price'];
}

you’re still using the wrong quotation marks (why aren’t you getting an error message for that?), and you’re still not using the simpler way of calculating the price that @rpkamp showed you.

Thanks for all the replies.
Between fixing the code that “looks better now” and the “wrong quotation marks”, apparently that was the remedy. It woks successfully now, after several tests. Much thanks

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