-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgames.php
More file actions
177 lines (173 loc) · 7.73 KB
/
games.php
File metadata and controls
177 lines (173 loc) · 7.73 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php include('includes/header.php')
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Games Management</title>
<link rel="stylesheet" href="../styling.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<form method="post" >
<input style="border-radius: 6px;" type="text" name="search" placeholder="Search Anything ...">
<button type="submit" name="validate" class="btn btn-info btn-sm">search</button>
</form>
<div class="container">
<button class="btn btn-info my-5" id="addbtn">Add Game</button>
<div class="card-content ">
<?php
$connect = mysqli_connect('localhost', 'root', '', 'assoc');
$sql = "SELECT * FROM games";
$result = mysqli_query($connect, $sql);
if(isset($_POST['validate'])){
$input=$_POST['search'];
$sql="select * from games where game_id='$input' or game_name='$input' or game_title='$input' or game_website='$input'";
$result =mysqli_query($connect,$sql);
if($result){
while ($row = mysqli_fetch_assoc($result)) {
$game_id = $row['game_id'];
$game_name = $row['game_name'];
$game_title = $row['game_title'];
$game_website = $row['game_website'];
$game_img = $row['game_img'];
?>
<div class="card1">
<div class="card-image">
<img src="../images/<?php echo $row['game_img'] ?>" alt="">
</div>
<div class="card-info">
<h3><?php echo $game_name ?></h3>
<p><?php echo $game_title ?></p>
</div>
<div class="buttons">
<button class="btn btn-info"><a href="<?php echo $game_website ?>" ><i class="fa-solid fa-laptop"></i></a></button>
<button class="btn btn-info"><a href="updateGame.php?updatedid=<?php echo $row['game_id']; ?>"><i class="fa-solid fa-pen-to-square"></i></a></button>
<button class="btn btn-info"><a href="deleteGame.php?deletedid=<?php echo $row['game_id']; ?>"><i class="fa-solid fa-trash"></i></a></button>
</div>
<div id="content" style="display: none;">
<p><?php echo $row['speakers'] ?>
</p>
</div>
</div>
<?php
}
}
}
if ($result && mysqli_num_rows($result) > 0) {
#search code starts here
while ($row = mysqli_fetch_assoc($result)) {
$game_id = $row['game_id'];
$game_name = $row['game_name'];
$game_title = $row['game_title'];
$game_website = $row['game_website'];
$game_img = $row['game_img'];
?>
<div class="card1">
<div class="card-image">
<img src="../images/<?php echo $row['game_img'] ?>" alt="">
</div>
<div class="card-info">
<h3><?php echo $game_name ?></h3>
<p><?php echo $game_title ?></p>
</div>
<div class="buttons">
<button class="btn btn-info"><a href="<?php echo $game_website ?>" ><i class="fa-solid fa-laptop"></i></a></button>
<button class="btn btn-info"><a href="updateGame.php?updatedid=<?php echo $row['game_id']; ?>"><i class="fa-solid fa-pen-to-square"></i></a></button>
<button class="btn btn-info"><a href="deleteGame.php?deletedid=<?php echo $row['game_id']; ?>"><i class="fa-solid fa-trash"></i></a></button>
</div>
<div id="content" style="display: none;">
<p><?php echo $row['speakers'] ?>
</p>
</div>
</div>
<?php
}
} else {
// Handle case where there are no games
echo "<p>No games found.</p>";
}
?>
</div>
</div>
<div class="container mt-5" id="add_game">
<h2 >Add Game</h2>
<?php
$conn=mysqli_connect('localhost','root','','assoc');
if (isset($_POST['submit'])){
$game_id=$_POST['game_id'];
$game_name=$_POST['game_name'];
$game_title=$_POST['game_title'];
$game_website=$_POST['game_website'];
/*image part*/
$file_name=$_FILES['image']['name'];
$tempname=$_FILES['image']['tmp_name'];
$folder='../images/'.$file_name;
/*image part*/
$select="select *from games where game_id= '$game_id'";
$res = mysqli_query($conn, $select);
if(mysqli_num_rows($res)>0){
echo "the game already exists";
}else{
/*INSERT INTO `games`(`game_id`, `game_name`, `game_title`, `game_website`, `game_img`) VALUES ('[value-1]','[value-2]','[value-3]','[value-4]','[value-5]')*/
$query="insert into games(game_id,game_name,game_title,game_website,game_img) VALUES ('$game_id','$game_name','$game_title','$game_website','$file_name') ";
$result=mysqli_query($conn,$query);
if(move_uploaded_file($tempname,$folder)){
echo "";
}else {
echo "it was not uploaded try again";
}
if($result){
echo "data was inserted";
}
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="game_id">Game Number:</label>
<input name="game_id" style="width: 900px;" type="number" class="form-control" id="game_id" required placeholder="Enter the game number">
</div>
<div class="form-group">
<label for="game_name">Game Name:</label>
<input name="game_name" style="width: 900px;" type="text" class="form-control" id="game_name" required placeholder="Enter the game title">
</div>
<div class="form-group">
<label for="game_title">Add Description:</label>
<textarea name="game_title" class="form-control" id="game_title" rows="3" placeholder="Enter a game description"></textarea>
</div>
<div class="form-group">
<label for="game_img">Event Image:</label>
<input type="file" name="image" class="form-control" id="image"/>
</div>
<div class="form-group">
<label for="game_website">Game Website:</label>
<input type="text" name="game_website" class="form-control" id="game_website" placeholder="Enter game website">
</div>
<button type="submit" name="submit" class="btn btn-info">Add Game</button>
</form>
</div>
<!-- Bootstrap JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// JavaScript code to handle the click event and scroll to the addUserSection
document.addEventListener("DOMContentLoaded", function() {
// Find the "Add User" button or link (replace 'addUserButton' with the actual id or class of your button/link)
var addUserButton = document.getElementById("addbtn");
// Add click event listener
addUserButton.addEventListener("click", function(event) {
event.preventDefault(); // Prevent default action of the button/link
// Scroll to the addUserSection
document.getElementById("add_game").scrollIntoView({
behavior: "smooth" // You can change this to "auto" for instant scrolling
});
});
});
</script>
</body>
</html>
<?php include('includes/footer.php') ?>