i already got message in my browser
Notice: Undefined variable: password in C:\xampp\htdocs\udemy\mysql\login.php on line 8 pls insert username and password
even i haven't submitted the form.
One more question how can i validate if the username and the password are submit with text.
<?php
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
}
if($username && $password){
echo $username;
echo $password;
}else{
echo "pls insert username and password";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"
>
</head>
<body>
<div class="container">
<div class="col-sm-6">
<form action="login.php" method="POST">
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username"
class="form-control">
</div>
<div class="form-group">
<label for="username">Password</label>
<input type="password" name="password"
class="form-control">
</div>
<div class="form-group">
<input type="submit" name="submit"
class="btn btn-primary">
</div>
</form>
</div>
</div>
</body>
</html>
$_POST['submit']is not set you aren't defining the variables you are trying to use in the next conditional. Put the second conditional inside the first one. Yourif(isset($_POST['submit'])){is checking if the form was submitted.