Please help with php. I had this code working before when I had a separate php file and separate html file, but for some reason now it's not working when I try to combine them together into index.php
.
this is the error that i'm getting:
Undefined index: username
Undefined index: password
I tried using if(isset($_POST['submit']))
for $username/$password
but this didn't change anything
<html>
<body>
<form action="index.php" method="post">
<table border="0">
<tr bgcolor="#cccccc">
<td width="150">Username: </td>
<td width="20"><input type="text" name="username" size="15"
maxlength="15"></td>
</tr>
<tr>
<tr bgcolor="#cccccc">
<td width="150">Password: </td>
<td width="20"><input type="password" name="password" size="15"
maxlength="15"></td>
</tr>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
trim($username);
trim($password);
$usernameArr = array( 1 => "a",
2 => "b",
3 => "c",
4 => "d",
5 => "e",
6 => "f",
7 => "g",
8 => "h",
9 => "i",
10 => "j");
$passwordArr = array( 1 => "pass1",
2 => "pass2",
3 => "pass3",
4 => "pass4",
5 => "pass5",
6 => "pass6",
7 => "pass7",
8 => "pass8",
9 => "pass9",
10 => "pass0");
$varBool = false;
for ( $i = 1; $i <= 10; $i++){
if ($username == $usernameArr[$i] && $password === $passwordArr[$i]){
$varBool = true;
}
}
If ($varBool){
echo "You have successfully logged in!";
}
else{
echo "Sorry, wrong information has been entered!";
}
?>