-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.php
More file actions
92 lines (57 loc) · 1.85 KB
/
connection.php
File metadata and controls
92 lines (57 loc) · 1.85 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
<?php
// Database configuration
$servername = 'localhost';
$username = 'root';
$password = "";
$dbname = 'gamerhive';
// Connect to the database
$conn = mysqli_connect($servername, $username,$password,$dbname);
// Check if the connection was successful
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Define the user details
$email = $_POST['email'];
$password = $_POST['password'];
$username = $_POST['username'];
$mobile = $_POST['phone'];
$dob = $_POST['dob'];
// Hash the password
//to check the login
function check_login($con)
{
if(isset($_SESSION['user_id']))
{
$id = $_SESSION['user_id'];
$query = "select * from users where user_id = '$id' limit 1";
$result = mysqli_query($con,$query);
if($result && mysqli_num_rows($result) > 0)
{
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
}
//redirect to login
header("Location: /index.php");
die;
}
// Insert the user into the database
$sql = "INSERT INTO registration(email, password, username, mobile, DOB) VALUES ('$email', '$password', '$username', '$mobile', '$dob')";
if (mysqli_query($conn, $sql)) {
echo "Registration successfully...";
header("Location:login.html");
echo"<script>alert('Welcome to GamerHive')</script>";
echo"<script>window.open('login.html')</script>";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
if (mysqli_affected_rows($conn) > 0) {
echo "Data inserted successfully";
} else {
echo "Data not inserted";
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
die("Connection failed: " . mysqli_connect_error());
}
// Close the database connection
mysqli_close($conn);
?>