-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateUser.php
More file actions
34 lines (29 loc) · 906 Bytes
/
CreateUser.php
File metadata and controls
34 lines (29 loc) · 906 Bytes
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
<?php
include_once("./library.php"); // To connect to the database
session_start();
$_SESSION["user"] = $_POST["username"];
$con = new mysqli($SERVER, $USERNAME, $PASSWORD, $DATABASE);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sqlAllUsers = "SELECT user_id FROM User";
$result = mysqli_query($con,$sqlAllUsers);
// Form the SQL query (an INSERT query)
$sql="INSERT INTO User (user_id, username, password, location, rating)
VALUES
(" . mysqli_num_rows($result) . ", '$_POST[username]','$_POST[password]','$_POST[location]', 'N/A')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
redirect('http://localhost:8080/database_project/homepage.html');
mysqli_close($con);
function redirect($url) {
ob_start();
header('Location: '.$url);
ob_end_flush();
die();
}
?>