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.

  • Similar Content

    • By Konti.
      Salut, am eroarea data :

      PHP Parse error:  syntax error, unexpected '?'

      la linia :
       
      protected function finishSave(array $options)
          {
              $this->fireModelEvent('saved', false);
              if ($this->isDirty() && ($options['touch'] ?? true)) {
                  $this->touchOwners();
              }
              $this->syncOriginal();
          }
       
       
    • By Huzam Mazuh
      Salutare,
       
      In luna Martie am lansat platforma cu cele mai multe joburi pentru tineri, numita SmartDreamers: http://smartdreamers.com/
       
      Constant avem aproximativ 50% din oferta de joburi din domeniul IT. In acest topic voi posta frecvent top joburi din IT, joburi individuale, interviuri cu IT-isti si alte informatii relevante pentru dezvoltarea personala si gasirea unui job.
       
      Incep cu 10 pozitii de Java Developers in Bucuresti, oferite de EEU Software: http://smartdreamers.com/en/job-Java-developer-EEU-Software-SRL/1470/
       
      Spor si o zi frumoasa!
       
       
    • By inginerul
      Salut. Siteul meu este http://www.tutorialeweb.net ce contine tutoriale pentru incepatori legate de limbajele xhtml, css, javascript, php si mysql. Siteul mai contine un tutorial de AutoCAD iar pe viitor vor urma tutoriale despre Catia, SolidWorks si Inventor deoarece sunt pe domeniu.
      Aveti ceva pareri si/sau sugestii?
×
×
  • 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.