Jump to content

Problemă login script de register/login/logout?


Daizuke

Recommended Posts

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!

Link to comment
Share on other sites

  • gaby changed the title to Problemă login script de register/login/logout?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.