Spaces:
Sleeping

pde / signup.php
Pezh's picture
Create signup.php
2397633 verified
Raw History Blame Contribute Delete
1.04 kB
<?php
// Assuming you have already established a database connection
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = $_POST["password"];
// Check if the username already exists in the database
$checkQuery = "SELECT * FROM users WHERE username='$username'";
$checkResult = mysqli_query($connection, $checkQuery);
if (mysqli_num_rows($checkResult) == 0) { // Username is available, add user to the database
$insertQuery = "INSERT INTO users (username, password) VALUES ('$username', '$password')";
if (mysqli_query($connection, $insertQuery)) {
// User successfully added, redirect to video page
header('Location: videos.php');
exit();
} else {
echo "Error: " . $insertQuery . "<br>" . mysqli_error($connection);
}
} else { // Username already exists, display an error or redirect back to signup form
echo "Username already exists. Please choose a different username.";
}
}
?>