-2

Hello experts I would be very happy about your help

The aim of the code is that the user can register. So it should store the values of form id="signup"

should be stored in the mysql database.

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>Mahlzeit</title>
  <link rel="stylesheet" href="./Login.css">
</head>

<!DOCTYPE html>
<html>
<head>
    <title>Slide Navbar</title>
    <link rel="stylesheet" type="text/css" href="slide navbar Login.css">
<link href="https://fonts.googleapis.com/css2?family=Jost:wght@500&display=swap" rel="stylesheet">
</head>
<body>
    <div class="main">      
        <input type="checkbox" id="chk" aria-hidden="true">
            <div class="signup">
                <form action="http://localhost/Kulinarik/signup_save.php" methode="POST" id="signup">
                    <label for="chk" aria-hidden="true">Sign up</label>
                    <input type="text" name="vorname" placeholder="Vorname" id="vorname">
                    <input type="text" name="nachname" placeholder="Nachname" id="nachname">
                    <input type="email" name="email" placeholder="Email" id="email">
                    <button type="submit" value="signup">Sign up</button>
                </form>
            </div>
            <div class="login">
                <form action="login_save.php" methode="POST" id="login">
                    <label for="chk" aria-hidden="true">Login</label>
                    <input type="email" name="email" placeholder="Email" required=""/>
                    <input type="password" name="pswd" placeholder="Password" required=""/>
                    <button type="submit" value="Login">Login</button>
                    <a class="changepassword">Passwort ändern</a>
                </form>
            </div>
        </input>
    </div>
</body>
</html>

</body>
</html>

and the connection

    <?php
    session_start();
?>
<?php
$con= mysqli_connect('localhost','root','123456', 'userdata',);
$email = $_POST['email'];
$vorname = $_POST['vorname'];
$nachname = $_POST['nachname'];
$passwort = rand(0, 999999);


$result = $con->query("SELECT email FROM signup WHERE email = $email");
if($result->num_rows == 0) {
    $sql = "INSERT INTO signup (vorname, nachname, email, Passwort) vALUES ($vorname, $nachname, $email, $passwort)";
    if ($con->query($sql) === TRUE) {
        header("Location: Login.html");
      } else {
        echo "Error: " . $sql . "<br>" . $con->error;
      }
} else {
    echo "User ist bereits registriert";
}
$mysqli->close();

?>

Do you notice an error ?

The error message says that the array keys are not defined

e.g.:Warning: Undefined array key "email" in C:\xampp\htdocs\Kulinarik\signup_save.php on line 9

Thanks in advance Hello experts I would be very happy about your help

Etzi138
  • 29
  • 6
  • Also and more important : please printout your error. – Shlomtzion Dec 07 '21 at 10:40
  • 1
    You have many errors along the way: methode=?! should be method= <- important , also required="" is not needed just requied. – Shlomtzion Dec 07 '21 at 10:44
  • Thanks for your input The code does not take the values which are input. there is nothing in $_POST ["email"]; But i cant see why – Etzi138 Dec 07 '21 at 10:44
  • 1
    Fix methode="post" to method="post" and the data will be posted... you are doing a GET right now... I checked it. – Shlomtzion Dec 07 '21 at 10:51
  • @Shlomtzion you where right. Thanks the typos are weird because i downloaded a template Did not expect this – Etzi138 Dec 07 '21 at 10:52
  • Remove the spaces before the ` – RiggsFolly Dec 07 '21 at 11:00
  • ___Small Point___ If your password is a randomly generated number ... How do you expect to be able to guess it so you can actually logon – RiggsFolly Dec 07 '21 at 11:02
  • 1
    _i downloaded a template_ Then throw is away there are lots of typos in it – RiggsFolly Dec 07 '21 at 11:04
  • 1
    Just because someone provided a template doesn't mean it's infallible. Everyone makes mistakes. Not every blogger on the net is automatically a code guru. There is a whole pile of junk out there provided by people who don't know much about coding but perhaps know a bit about how to sell ad views/clicks by updating a blog every week. – ADyson Dec 07 '21 at 11:07
  • @RiggsFolly The random passwortr will be sent to the new user per Email and then he can choose a new on. – Etzi138 Dec 07 '21 at 11:53

1 Answers1

1

Replace:

<form action="" methode="POST" id="signup">

With

<form action="" method="POST" id="signup">

And your data will be posted... not sent in the URL...

If you do a :

print_r($_POST);
print_r($_GET);
die;

in the signup_save.php in the beginning and just die; afterwards you will see the values and they also appear in the URL.

Shlomtzion
  • 674
  • 5
  • 12