Jump to content

memedmax

New Members
  • Posts

    1
  • Joined

  • Last visited

memedmax's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi everyone, i'm stuck on my project for about 3days and really need some help please : i cant add any data to my phpmyadmin database and don't know why, Here are my files Login.php <?php require 'config.php'; if(!empty($_SESSION["id"])){ header("Location: index.php"); } if(isset($_POST["submit"])){ $usernameemail = $_POST["usernameemail"]; $password = $_POST["password"]; $result = mysqli_query($conn, "SELECT * FROM tb_user WHERE username = '$usernameemail' OR email = '$usernameemail'"); $row = mysqli_fetch_assoc($result); if(mysqli_num_rows($result) > 0){ if($password == $row['password']){ $_SESSION["login"] = true; $_SESSION["id"] = $row["id"]; header("Location: index.php"); } else{ echo "<script> alert('Wrong Password'); </script>"; } } else{ echo "<script> alert('User Not Registered'); </script>"; } } ?> <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Login</title> </head> <body> <h2>Login</h2> <form class="" action="" method="post" autocomplete="off"> <label for="usernameemail">Username or Email : </label> <input type="text" name="usernameemail" id = "usernameemail" required value=""> <br> <label for="password">Password : </label> <input type="password" name="password" id = "password" required value=""> <br> <button type="submit" name="submit">Login</button> </form> <br> <a href="registration.php">Registration</a> </body> </html> <?php session_start(); $conn = mysqli_connect("localhost", "root", "root", "reglog"); <?php require 'config.php'; $_SESSION = []; session_unset(); session_destroy(); header("Location: login.php"); <?php require 'config.php'; if(!empty($_SESSION["id"])){ header("Location: index.php"); } if(isset($_POST["submit"])){ $name = $_POST["name"]; $username = $_POST["username"]; $email = $_POST["email"]; $password = $_POST["password"]; $confirmpassword = $_POST["confirmpassword"]; $duplicate = mysqli_query($conn, "SELECT * FROM tb_user WHERE username = '$username' OR email = '$email'"); if(mysqli_num_rows($duplicate) > 0){ echo "<script> alert('Username or Email Has Already Taken'); </script>"; } else{ if($password == $confirmpassword){ $query = "INSERT INTO tb_user VALUES('','$name','$username','$email','$password')"; mysqli_query($conn, $query); echo "<script> alert('Registration Successful'); </script>"; } else{ echo "<script> alert('Password Does Not Match'); </script>"; } } } ?> <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Registration</title> </head> <body> <h2>Registration</h2> <form class="" action="" method="post" autocomplete="off"> <label for="name">Name : </label> <input type="text" name="name" id = "name" required value=""> <br> <label for="username">Username : </label> <input type="text" name="username" id = "username" required value=""> <br> <label for="email">Email : </label> <input type="email" name="email" id = "email" required value=""> <br> <label for="password">Password : </label> <input type="password" name="password" id = "password" required value=""> <br> <label for="confirmpassword">Confirm Password : </label> <input type="password" name="confirmpassword" id = "confirmpassword" required value=""> <br> <button type="submit" name="submit">Register</button> </form> <br> <a href="login.php">Login</a> </body> </html> <?php require 'config.php'; if(!empty($_SESSION["id"])){ $id = $_SESSION["id"]; $result = mysqli_query($conn, "SELECT * FROM tb_user WHERE id = $id"); $row = mysqli_fetch_assoc($result); } else{ header("Location: login.php"); } ?> <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Index</title> </head> <body> <h1>Welcome <?php echo $row["name"]; ?></h1> <a href="logout.php">Logout</a> </body> </html>
×
×
  • 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.