Hello I have setup my Signup page but I am getting this error Notice: Undefined index: signup in C:\xampp\htdocs\Marcus\signup.php on line 27
The error is coming from my HTML as it uses $_GET to see the URL and see check to see if their are errors with the input of the form and to display error messages,the error messages and the success message do work its just when you click on the signup button and it goes into a different HTML the error shows up, but as soon as one of the errors are true it goes away. any help at all would be great!
HTML for my signup page
require "header.php";
?>
<main>
<h1 class="signup_text2">Signup</h1>
<link rel="stylesheet" type="text/css" href="style.css">
<?php
if (isset($_GET['error'])) {
if ($_GET['error'] == "emptyfields") {
echo '<p class="error1"> Fill in all feilds!!</p>';
}elseif ($_GET['error'] == "invaildmailuid") {
echo '<p class="error2"> Invalid Username And Email! </p>';
}elseif ($_GET['error'] == "invaliduid") {
echo '<p class="error3"> Invalid Username </p>';
}elseif ($_GET['error'] == "invalidmail") {
echo '<p class="error4"> Invalid E-mail! </p>';
}elseif ($_GET['error'] == "passswordcheck") {
echo '<p class="error5"> Your Passwords do not match! </p>';
}elseif ($_GET['error'] == "usertaken") {
echo '<p class="error6"> Username is already taken! </p>';
}
}elseif ($_GET['signup'] == "success") {
echo '<p class="success1"> Signup Successful!</p>';
}
?>
<form action="includes/signup.inc.php" method="post">
<input class="signup-Username" type="text" name="uid" placeholder="Username">
<input class="signup-Email" type="text" name="mail" placeholder="E-mail">
<input class="signup-Password" type="password" name="pwd" placeholder="Password">
<input class="signup-Password2" type="password" name="pwd-repeat" placeholder="Repeat Password">
<button class="signup_btn" type="sumbit" name="signup-submit">Signup</button>
</form>
</main>
PHP signup code
<?php
if (isset($_POST['signup-submit'])) {
require 'dbh.inc.php';
$username = $_POST['uid'];
$email = $_POST['mail'];
$password = $_POST['pwd'];
$passwordRepeat = $_POST['pwd-repeat'];
if (empty($username) || empty($email) || empty($password) || empty($passwordRepeat)) {
header("Location: ../signup.php?error=emptyfields&uid=".$username."&mail=".$email);
exit();
}elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invaildmailuid");
exit();
}elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../signup.php?error=invaildmail&uid=".$username);
exit();
}elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invailduid&mail=".$email);
exit();
}elseif ($password !== $passwordRepeat) {
header("Location: ../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
exit();
}else{
$sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../signup.php?error=sqlerror1");
exit();
} else {
mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if ($resultCheck > 0) {
header("Location: ../signup.php?error=usertaken&mail=".$email);
exit();
} else {
$sql = "INSERT INTO users (uidUsers, emailUsers, pwdUsers) VALUES (?, ?, ?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../signup.php?error=sqlerror");
exit();
} else {
$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hashedPwd);
mysqli_stmt_execute($stmt);
header("Location: ../signup.php?signup=success");
exit();
}
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}else {
header("Location: ../signup.php");
exit();
}