-
Notifications
You must be signed in to change notification settings - Fork 1
/
buy_list.php
80 lines (69 loc) · 3.2 KB
/
buy_list.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
include "config.php";
$price =$_POST['value'];
$owner=$_POST['buyerAddress'];
$ownerAddress=$_POST['sellerAddress'];
$NFT_image=$_POST["NFT_image"];
$NFT_name=$_POST["NFT_name"];
$resell=$_POST["resell"];
$id=$_POST['tokenid'];
$collection=$_POST['collection'];
$currency = $_POST['currency'];
// query for buyer information
$query1 = "SELECT `Id`, `Username`,`Userimage` FROM `nft_user` WHERE Useraddress='{$owner}'";
$result1 = $link->query($query1);
$res=$result1->fetch_assoc();
$userimage= $res['Userimage'];
$OwnerName= $res['Username'];
// query fo seller information
$query2 = "SELECT `Id`, `Username`,`Userimage` FROM `nft_user` WHERE Useraddress='{$ownerAddress}'";
$result2 = $link->query($query2);
$res1=$result2->fetch_assoc();
$sellerimage= $res1['Userimage'];
$sellerName= $res1['Username'];
date_default_timezone_set("Asia/Kolkata");
$date=date("Y/m/d");
// query for buy tabel
// $databuy=mysqli_query($link,"select * from NFT_buy where NFT_id='{$id}' AND Address='{$owner}'");
// if(mysqli_num_rows($databuy)==0)
// {
$query="INSERT INTO `NFT_buy`( `Username`, `image`,`Address`, `value`, `time`,`NFT_image`,`NFT_name`,`NFT_id`,`collection`,`currency`)
VALUES ('{$OwnerName}','{$userimage}','{$owner}','{$price}','{$date}','{$NFT_image}','{$NFT_name}','{$id}','{$collection}','{$currency}')";
$result=mysqli_query($link,$query);
if($result){
$sqlnew = "INSERT INTO `Nft_activity` ( `Nft_name`, `Nft_image`, `nft_type`, `Date`,`Address`,`Nft_id`,`Nft_price`)
VALUES ( '$NFT_name', '$NFT_image', 'Bought', '$date','$owner','$id','$price')";
$datanew = mysqli_query($link, $sqlnew);
}
else{
echo "failed BUY ";
}
// }else{
// $buyRow=mysqli_fetch_assoc($databuy);
// $buyAmount=$buyRow['value']+$price;
// $buyUpdate=mysqli_query($link,"UPDATE `NFT_buy` SET `value`='$buyAmount' WHERE `Address`='{$owner}' AND `NFT_id`='{$id}'");
// }
// query for sell tabel
// $databuy=mysqli_query($link,"select * from Nft_sell where NFT_id='{$id}' AND Address='{$owner}'");
// if(mysqli_num_rows($databuy)==0)
// {
$queryseller="INSERT INTO `Nft_sell`( `Username`, `image`,`Address`, `value`, `Time`,`Nft_image`,`NFT_name`,`nft_id`,`collection`,`currency`)
VALUES ('{$OwnerName}','{$userimage}','{$ownerAddress}','{$price}','{$date}','{$NFT_image}','{$NFT_name}','{$id}','{$collection}','{$currency}')";
$resultseller=mysqli_query($link,$queryseller);
if($resultseller){
$sqlnew = "INSERT INTO `Nft_activity` ( `Nft_name`, `Nft_image`, `nft_type`, `Date`,`Address`,`Nft_id`,`Nft_price`)
VALUES ( '$NFT_name', '$NFT_image', 'Sold', '$date','$ownerAddress','$id','$price')";
$datanew = mysqli_query($link, $sqlnew);
}
else{
echo "failed SEll";
}
// }else{
// $buyRow=mysqli_fetch_assoc($databuy);
// $buyAmount=$buyRow['value']+$price;
// $buyUpdate=mysqli_query($link,"UPDATE `Nft_sell` SET `value`='$buyAmount' WHERE `Address`='{$owner}' AND `NFT_id`='{$id}'");
// }
//Query For Update Owner
$update="UPDATE NFT_info SET `NFT_owner_address`='$owner',`NFT_resell`='$resell',`last_price`='$price',`last_buy_currency`='$currency' WHERE NFT_id='$id' ";
$dataupdate=mysqli_query($link,$update);
?>