Setting a minimum price

I am using a php web video script (that I didn’t write) which allows Users to purchase videos and allows the video uploader to change the default price (set by Admin). I am trying to get help modifying the script so that an Uploader can’t change the price below the Admins’ default price.

I know some things about this code script - when the Admin sets a video purchase price that number/value appears in the config table under the name: video_play_price (this should be the minimum price).

That same Admin set number also appears in the videos table, under the column videos_play_price, but when the User/Uploader changes the price, the price changes there (in the videos table > videos_play_price column). So, based on all that, I attempted to modify the file, by adding lines 30, 32,32 and 46(in Bold), without success. I look forward to hearing about what I need to correct, to try again. Thanks

<?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’ => $temp_price,**
	    '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'],1)

));

In this extract from your code

'TAGS' => $video->tags,
**‘video_play_price’ => $temp_price,**
'video_play_price' => $u_paid_videos->video_play_price,

did you remember to remove the line immediately after the one you marked, which assigns a different value to the same array element?

If not, can you elaborate on “without success” please?

Thanks for your reply.

I think you’re saying to remove this line of code?

// 'video_play_price' => $u_paid_videos->video_play_price,

like so, below:

$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’ => $temp_price,
	   // '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'],1)

));

And by success I mean that the Admin default price is 2, and I change, (as a User) the price to 1, it stays that way (no success), but if my minimum price code was correct, that wouldn’t be allowed.

I am guessing something may also need to be changed with the html (where the User edits the price)? Here’s that code:

					<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="text" name="video_play_price" class="form-control input-md" value="{{video_play_price_user}}">
					</div>
					</div>

Any additional guidance will be appreciated.

Yes.

I am confused - when you say it allowed you to store the lower price, was that with the line above in place, or removed? Do the different-style quotes make any difference, or is that just in the post here?

Maybe. Is it correct that the name of that field is video_play_price, but you populate it with the value of video_play_price_user?

In your PHP code, should video_play_price_user use $temp_price rather than video_play_price?

Does this line of code work without an error?

**    $temp_price = $videos->video_play_price;**

Where does the $videos object come from?

You could add some client side validation by making that form input a number tyoe with a min value.

Though this will only help in stopping honest users inadvertantly selecting a value too low. You will still need the server side validation to be secure.
But that does not make client side validation redundant, it’s better for UX if it’s harder for users to make errors and have to sublit the form again.

This is a little off-topic, but since you ask about changing the html…

Thanks again for the replies.
It allows the User to change to any price, lower or higher, with and without this line:

'video_play_price' => $u_paid_videos->video_play_price,

I didn’t write this code, so, the answer to your question " Is it correct that the name of that field is video_play_price , but you populate it with the value of video_play_price_user ?", is I think so. This line pertains to that field, I believe:

'video_play_price_user' => number_format($video->video_play_price?$video->video_play_price:$config['video_play_price'],1)

Regarding " should video_play_price_user use $temp_price rather than video_play_price ?" Yes, I think you are correct.

Does this line of code work without an error?

**    $temp_price = $videos->video_play_price;**

Yes

Where does the $videos object come from?
– what should it be?

I look forward to your reply.

I don’t know as there’s obviously more code somewhere, but if you look at every other line that uses similar variables, it uses the $video object, without an ‘s’ on the end. Maybe it doesn’t throw an error because you have created a $videos object somewhere else, or maybe you have error reporting disabled.

Thanks again for your reply/help.
I have this:

$min_price=$config[‘video_play_price’]; // in db > config table > video_play_price column - is where admin's default price is stored 

$temp_price = $videos[‘video_play_price’]; //in db > videos table > video_play_price column - is where uploader price changes are stored 

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

I believe I just need to reflect this where it saves the video price in “video_play_price_user”, which, I believe is this line:

'video_play_price_user' => number_format($video->video_play_price?$video->video_play_price:$config['video_play_price'],1)

Any additional guidance will be welcomed.

I ask again, though - where has $videos come from, to be able to use $videos['video_play_price'] in your code?

Look very carefully at every other place that you access attributes from the videos table. Or read comment #7 above where I spelled out exactly what I think might be wrong with it. It might be me, but there’s an inconsistency there that might make a difference.

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