So im trying to build a login system via a tutorial and it worked fine. But as soon as I started to change something in my code the button that submits your data will just return you to the index.html without it even being mentioned in the entire relevant code.
i got a header.php:
<?php
session_start()
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/main.css">
</head>
<body>
<header>
<div class="container">
<img class="logo" src="img/logo.png" alt="logo">
<input class="searchbar" type="text" placeholder="Wonach suchen sie...">
<?php
if (isset($_SESSION['userId'])) {
echo '
<form class="headerlogin" action="includes/logout.inc.php" method="post">
<button id="logoutButton" type="submit" name="logout-submit">Logout</button>
</form>
</div>
</header>
';
}
else {
echo '
<form class="headerlogin" action="includes/login.inc.php" method="post">
<input class="mailinput" type="text" name="mailuid" placeholder="Benutzername/E-mail...">
<input class="pwdinput" type="password" name="pwd" placeholder="Passwort...">
<button class="loginButton" type="submit" name="login-submit">Login</button
</form>
<a href="signup.php">Signup</a>
</div>
</header>
';
}
?>
</div>
</nav>
</header>
then the signup page:
<?php require 'header.php'; ?>
<main>
<h1>Signup</h1>
<?php
if (isset($_GET['error'])) {
if($_GET['error'] == "emptyfields") {
echo '<p id="signuperror"> Füllen sie bitte alle Felder aus.</p>';
}
else if($_GET['error'] == "invalidmailuid") {
echo '<p id="signuperror"> Der Benutzername darf nur aus Buchstaben und Zahlen bestehen.</p>
<p id="signuperror"> Bitte geben sie eine echte E-mail Adresse an.</p>';
}
else if($_GET['error'] == "invalidmail") {
echo '<p id="signuperror"> Bitte geben sie eine echte E-mail Adresse an.</p>';
}
else if($_GET['error'] == "invaliduid") {
echo '<p id="signuperror"> Der Benutzername darf nur aus Buchstaben und Zeichen bestehen.</p>';
}
else if($_GET['error'] == "passwordcheck") {
echo '<p id="signuperror"> Die Passwörter sind nicht identisch.</p>';
}
else if($_GET['error'] == "usertaken") {
echo '<p id="signuperror"> Der Benutzername ist bereits vergeben.</p>';
}
}
else if (isset($_GET['signup'])) {
if ($_GET['signup'] == "success"){
echo '<p id="signupsuccess"> Glückwunsch! Sie haben sich erfolgreich registriert! </p>';
}
}
?>
<form action="includes/signup.inc.php" method="post">
<input type="text" name="uid" placeholder="Benutzername">
<input type="text" name="mail" placeholder="E-Mail Adresse">
<input type="password" name="pwd" placeholder="Passwort">
<input type="password" name="pwd-repeat" placeholder="Passwort wiederholen">
<button type="submit" name="signup-submit">Registrieren</button>
</form>
</main>
<?php require 'footer.php'; ?>
and the footer.php
</body>
</html>
In signup.php the signup-submit button should submit your data to signup.inc.php but it just takes you back to index.html
Your form will not redirect to signup.php.and your form request method is post but in signup.php file you try to get variables in $_GET. change this one to $_POST. change your code in header.php:
<?php
if (isset($_SESSION['userId'])) {
echo '
<form class="headerlogin" action="includes/logout.inc.php" method="post">
<button id="logoutButton" type="submit" name="logout-submit">Logout</button>
</form>
</div>
</header>
';
}
else {
echo '
<form class="headerlogin" action="includes/signup.php" method="post">
<input class="mailinput" type="text" name="mailuid" placeholder="Benutzername/E-mail...">
<input class="pwdinput" type="password" name="pwd" placeholder="Passwort...">
<button class="loginButton" type="submit" name="login-submit">Login</button
</form>
<button type="submit">Signup</button>
</div>
</header>
';
}
?>
and signup.php :
<?php
if (isset($_POST['error'])) {
if($_POST['error'] == "emptyfields") {
echo '<p id="signuperror"> Füllen sie bitte alle Felder aus.</p>';
}
else if($_POST['error'] == "invalidmailuid") {
echo '<p id="signuperror"> Der Benutzername darf nur aus Buchstaben und Zahlen bestehen.</p>
<p id="signuperror"> Bitte geben sie eine echte E-mail Adresse an.</p>';
}
else if($_POST['error'] == "invalidmail") {
echo '<p id="signuperror"> Bitte geben sie eine echte E-mail Adresse an.</p>';
}
else if($_POST['error'] == "invaliduid") {
echo '<p id="signuperror"> Der Benutzername darf nur aus Buchstaben und Zeichen bestehen.</p>';
}
else if($_POST['error'] == "passwordcheck") {
echo '<p id="signuperror"> Die Passwörter sind nicht identisch.</p>';
}
else if($_POST['error'] == "usertaken") {
echo '<p id="signuperror"> Der Benutzername ist bereits vergeben.</p>';
}
}
else if (isset($_POST['signup'])) {
if ($_POST['signup'] == "success"){
echo '<p id="signupsuccess"> Glückwunsch! Sie haben sich erfolgreich registriert! </p>';
}
}
?>