Undefined variable: username in



define ('USERNAME', 'Stephenturkson');
define ('PASSWORD', 'something');

	$username = $_POST['username'];
	$username = $_POST['password'];


if( $username === USERNAME && $password === PASSWORD){

	$_SESSION['username'] = $username;
	header("Location: admin.php");

<!doctype html>
	<title>Login Form</title>

	form ul { padding: 0; margin: 0;}
	form li{ list-style: none; margin-bottom: 1em;}



<form action="index.php" method="post">
			<label for="name">Name: </label>
			<input name="name" type="text">

			<label for="password">Password: </label>
			<input name="password" type="password">

			<input type="submit" value="Login" name="submit">
$username = $_POST['username'];	
$username = $_POST['password'];

Did you mean to use the same varname?

If that doesn’t help, what was the question?


In your PHP code, you’re trying to retrieve a POST variable called ‘username’, but your form input is named ‘name’.

exactly. that was the issue
i couldnt sleep last night ,
thanks .

boss it was an issue with my html form its been solved. thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.