Daizuke Posted February 16, 2017 Report Share Posted February 16, 2017 După cum zice și titlul, am creat un coduleț de login/register/logout, dar nu merge..și nu înțeleg de ce. :/ Puțin ajutor, vă rog? index.php: <?php session_start(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP</title> </head> <body> <form action="login.php" method="POST"> <input type="text" name="username" placeholder="Username"><br> <input type="password" name="password" placeholder="Password"><br> <input type="submit" name="submit" value="Log in"> <?php if (isset($_SESSION['username'])) { echo "Welcome, ".$_SESSION['username']; } else { echo "You are not logged in!"; } ?> <br><br><br> <form action="signup.php" method="POST"> <input type="text" name="username" placeholder="Username"><br> <input type="email" name="email" placeholder="E-mail"><br> <input type="password" name="password" placeholder="Password"><br> <input type="submit" name="submit" value="Register"> </form> <form action="logout.php" method="POST"> <input type="submit" name="logout" value="Log out!"> </form> </body> </html> login.php: <?php session_start(); include 'connect.php'; $username = $_POST['username']; $password = $_POST['password']; $sql = "SELECT * FROM `test` WHERE username='$username' AND password='$password'"; $result = mysqli_query($conn, $sql); if(!$row = mysqli_fetch_assoc($result)) { echo "Your username/password is incorrect!"; } else { $_SESSION['username'] = $row['username']; } header("Location: index.php"); signup.php: <?php session_start(); include 'connect.php'; $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; $sql = "INSERT INTO `test` (username, email, password) VALUES ('$username', '$email', '$password')"; $result = mysqli_query($conn, $sql); header("Location: index.php"); Mulțumesc! Quote Link to comment Share on other sites More sharing options...
Moderators gadeas Posted February 19, 2017 Moderators Report Share Posted February 19, 2017 Ce eroare primesti? Quote PHP Developer - Not available for freelancing right now Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament Link to comment Share on other sites More sharing options...
Daizuke Posted February 20, 2017 Author Report Share Posted February 20, 2017 Mă pot înregistra, dar nu merge să mă loghez. Quote Link to comment Share on other sites More sharing options...
Moderators gadeas Posted February 20, 2017 Moderators Report Share Posted February 20, 2017 Ai verificat daca contu se inserteaza corect in baza de date? Quote PHP Developer - Not available for freelancing right now Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament Link to comment Share on other sites More sharing options...
Daizuke Posted February 20, 2017 Author Report Share Posted February 20, 2017 Da. Datele introduse în fișierul de register sunt introduse în db, dar nu mă pot loga, ca să-mi arate "welcome, nume" Quote Link to comment Share on other sites More sharing options...
Moderators gadeas Posted February 20, 2017 Moderators Report Share Posted February 20, 2017 Formu de login nu a fost niciodata inchis: </form> 1 Quote PHP Developer - Not available for freelancing right now Daca ai de gand sa postezi la categoria IPB, nu uita sa citesti regulamentul: Link regulament Link to comment Share on other sites More sharing options...
Daizuke Posted February 20, 2017 Author Report Share Posted February 20, 2017 Mersi! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.