/    Sign up×
Community /Pin to ProfileBookmark

Help with changing array and query in web video script

I’m trying to modify a web script (that I didn’t write).
The buy-video.php has this array:

“`
// 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, // the user who uploaded the video
‘video_title’ => $video->title, // storing the title
‘earned_amount’ => $up_amount,
‘time’ => $time_start,
‘short_id’ => $video->short_id,
‘session_key’ => $_SESSION[‘session_key’]
]);
“`

I’ve attempted to replace it with this:

“`
// add data to table
$insert_buy = $db->insert(‘videos_transactions’, [
‘user_id’ => $video->user_id,
‘paid_id’ => $user_id,
‘video_id’ => $video_id,
‘amount’ => $video_cost_new,
‘admin_com’ => $uploader_amount,
‘time’ => $time_start,
‘type’ => ‘rent’,
‘session_key’ => $_SESSION[‘session_key’]
]);
“`

without success, meaning that the user can proceed with a purchase of a video, and the ‘videos_transactions’ table populates, but no video player or video appears on the paid-videos page.

When I add this back in (to the buy-video.php):

“`
// 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’]
]);
“`

And re-test, the purchase proceeds and player and video appear on paid-videos page, (and both the ‘videos_transactions’ and the ‘u_paid_videos’ populate).

In paid-videos.php file is this:
`$get_videos = $db->rawQuery(“SELECT DISTINCT(v.id), v.* FROM u_paid_videos AS upv LEFT JOIN ” . T_VIDEOS . ” AS v ON (upv.id_video = v.id) WHERE upv.id_user = {$user->id} AND upv.session_key = ‘{$_SESSION[‘session_key’]}’ ORDER BY upv.id DESC”);`

when I comment this out, the video purchase doesn’t proceed to the paid-videos page at all.

I tried to replace that with this, without success:
`$get_videos = $db->rawQuery(“SELECT DISTINCT(v.id), v.* FROM videos_transactions AS vt LEFT JOIN ” . T_VIDEOS . ” AS v ON (vt.video_id = v.id) WHERE vt.user_id = {$user->id} AND vt.session_key = ‘{$_SESSION[‘session_key’]}’ ORDER BY vt.id DESC”);`

without success means, the video purchase doesn’t proceed to the paid-videos page at all.

So, I’m guessing this adds the purchase info into the ”u_paid_videos’ table:

“`
// add data to paid table
$insert_buy = $db->insert(‘u_paid_videos’, [
‘id_user’ => $user_id,
ETC.
“`

and this pulls the info out of the ”u_paid_videos ‘ table, to proceed with dsiplaying the video?
“`$get_videos = $db->rawQuery(“SELECT DISTINCT(v.id), v.* FROM u_paid_videos…etc. “`

Does that sound right?

If so, how can I get the web script to instead work with:

“`
// add data to table
$insert_buy = $db->insert(‘videos_transactions’, [
‘user_id’ => $video->user_id,
‘paid_id’ => $user_id,
ETC…
“`

and this:

“`$get_videos = $db->rawQuery(“SELECT DISTINCT(v.id), v.* FROM videos_transactions AS vt…ETC“`

Or what am I missing? Any guidance is appreciated

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 22.2021 — Hmm...that's an awful lot to digest right now for me. :)

My one hunch/suggestion is to look closely at the various "user ID" columns and variables being referenced, and make sure you're using the right one in each circumstance. At least it looks to me like they might represent more than one "user" thing?
Copy linkTweet thisAlerts:
@dmelnik3289Sep 24.2021 — At whatever point I have some spare energy, I visit blogs to get some valuable data. Today, I discovered your blog with the assistance of Google. Trust me; I thought that it is one of the most enlightening blog
×

Success!

Help @chrisjchrisj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...