Home » Php » php – Undefined Index 'username' line 3 undefined index 'password' line 5

php – Undefined Index 'username' line 3 undefined index 'password' line 5

Posted by: admin February 25, 2020 Leave a comment


I have been creating a login page and the sign up and login has been giving me the error in the title. been trying to fix this for hours scoured every question about this. Help
This is the whole code.

$username = $_GET["'username'"];
echo $username;
$password = $_GET["'password'"];
echo $password;

if (!empty($username)  ||  !empty($password)) {
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbname = "datalogin";

$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);

if(mysqli_connect_error()) {
    die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect());
}   else {
    $query = "SELECT password FROM users WHERE 
    $INSERT = "INSERT Into register (username, password) values(?, ?)";
if ($rnum==0) {
    $stmt = $conn->prepare($INSERT);
    $stmt->bind_param("ssssii", $username, $password);
    echo "New record inserted successfully";
    } else 

 echo "Someone already registered using this username";

     else {
      echo "All fields are required";

This is the html form code of the sign up page. Please help me find the error. Thanks.

<title>Login Form Design</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script type="text/javascript" src="table.js"></script>
<BODY style= "background: url(https://cdn4.vectorstock.com/i/1000x1000/76/13/polygon-abstract-texture-web-background-vector-4687613.jpg)" bgcolor=#FFFFFF text=#00CCF9>

    <div class="loginbox">
        <form action="insert.php" method="POST"
    <img src="avatar.png" class="avatar">
        <h1>Login Here</h1>
            <input type="text" name="" placeholder="Enter Username">
            <input type="password" name="" placeholder="Enter Password">
            <input type="submit" name="" value="Sign Up">

            <a href="#">Lost your password?</a><br>
            <a href="Signu.html">Don't have an account?</a>

How to&Answers: