-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrankscript.php
118 lines (108 loc) · 3.23 KB
/
rankscript.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
setcookie("error","",time()+1800,"/");
$temp="";
$maxrow =null;
if($_POST["category"]=="bollywood"){
$tablename = "Bollywood";
}
elseif($_POST["category"]=="world"){
$tablename = "World";
}
elseif($_POST["category"]=="punjabi"){
$tablename = "Punjabi";
}
elseif($_POST["category"]=="telgu"){
$tablename = "Telgu";
}
elseif($_POST["category"]=="romantic"){
$tablename = "Romantic";
}
elseif($_POST["category"]=="party"){
$tablename = "Party";
}
elseif($_POST["category"]=="ghazal"){
$tablename = "Ghazal";
}
elseif($_POST["category"]=="other"){
$tablename = "Other";
}
if(($_POST["rankcurrent"]=="") || ($_POST["rankexpect"]=="")){
setcookie("error","Current and Expected Rank of Song is Required",time()+1800,"/");
header("Location:admin.php");
exit();
}
require 'login_info1.php';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
setcookie("error","Database Connection failed",time()+1800,"/");
header("Location:admin.php");
}
$sql = 'select * from '.$tablename;
if($result = $conn->query($sql)){
$maxrow = $result->num_rows;
}
else{
setcookie("error","Undermined max row number",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
if(($maxrow >= $_POST["rankexpect"]) && ($maxrow >= $_POST["rankcurrent"]) ){
$sql = 'Update '.$tablename.' set rank = 50 where rank = '.$_POST["rankcurrent"];
if($conn->query($sql)){
if($_POST["rankcurrent"] < $_POST["rankexpect"]){
for($i=($_POST["rankcurrent"]+1); $i<= $_POST["rankexpect"];$i++){
$sql= 'update '.$tablename.' set rank = '.($i-1).' where rank = '.$i;
if($conn->query($sql)){}
else{
setcookie("error","Error in loop query",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
}
$sql = 'update '.$tablename.' set rank = '.$_POST["rankexpect"].' where rank=50';
if($conn->query($sql)){
setcookie("error","Rank Changed Succesfully",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
else{
setcookie("error","Last Query Failed",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
}
else{
for($i=($_POST["rankcurrent"]-1); $i>= $_POST["rankexpect"];$i--){
$sql= 'update '.$tablename.' set rank = '.($i+1).' where rank = '.$i;
if($conn->query($sql)){}
else{
setcookie("error","Error in loop query",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
}
$sql = 'update '.$tablename.' set rank = '.$_POST["rankexpect"].' where rank=50';
if($conn->query($sql)){
setcookie("error","Rank Changed Succesfully",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
else{
setcookie("error","Last Query Failed",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
}
}
else{
setcookie("error","Sql Query failed to save current rank",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
}
else{
setcookie("error","Please Enter valid rank",time()+1800,"/");
$conn->close();
header("Location:admin.php");
}
?>