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

Questions:

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.

<?php
$_SERVER["REQUEST_METHOD"] == "GET";
$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 
username='".mysql_real_escape_string($_POST['username'])."'";
    $INSERT = "INSERT Into register (username, password) values(?, ?)";
}
if ($rnum==0) {
    $stmt = $conn->prepare($INSERT);
    $stmt->bind_param("ssssii", $username, $password);
    $stmt->execute();
    echo "New record inserted successfully";
    } else 
{


 echo "Someone already registered using this username";



 }
    $stmt->close();
    $conn->close();
    } 
     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"
        <CENTER>
        <CENTER>
    <img src="avatar.png" class="avatar">
        <h1>Login Here</h1>
        <form>
            <p>Username</p>
            <input type="text" name="" placeholder="Enter Username">
            <p>Password</p>
            <CENTER>
            <input type="password" name="" placeholder="Enter Password">
            </CENTER>
            <CENTER>
            <input type="submit" name="" value="Sign Up">
            </CENTER>

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

</body>
</head>
</html>
How to&Answers: