forked from saivinayb/Online_Movie_Gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurchase.php
50 lines (40 loc) · 1.11 KB
/
purchase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
session_start();
$conn = new mysqli('localhost', 'root', '', 'mov_gallery');
$id=$_GET['id'];
$c_id=$_SESSION["id"];
$query = "SELECT balance from customer where c_id='$c_id'";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_assoc($result);
$currB = $row['balance'];
$query = "SELECT * from clips where vid_id = '$id'";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_assoc($result);
$title = $row['title'];
$price = $row['price'];
$cr_id = $row['cr_id'];
$query = "SELECT * from creator where cr_id = '$cr_id'";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_assoc($result);
$name = $row['cr_name'];
if($currB < $price)
{
echo 'LOW BALANCE.';
}
else
{
$sql="INSERT INTO purchase (vid_id, cr_id, c_id) VALUES ('$id','$cr_id','$c_id')";
if($conn->query($sql)===TRUE){
echo "PURCHASED!";
$sql2="UPDATE customer SET balance=balance-'$price' WHERE c_id='$c_id'";
$conn->query($sql2);
$sql3="UPDATE clips set sold=sold+1 where title='$title'";
$conn->query($sql3);
}
else
{
echo 'Connection error. Try again..';
echo("Error description: " . mysqli_error($conn));
}
}
?>