Well, not sure on your code as it is confusing a bit.
First, you create an array of names like this:
array $data {
array “Appin” {
entries url = >… password =>…}
and several others.
But, in the check to see if they are there, you check for array $data(username and password)
What happened to the top array of “Appin, Lucinda” and others.
In checking the $data array, you are not using the correct validation.
Inside the validation check: if($data[$_POST[‘username’]][‘password’] == $_POST[‘password’]) {
you check for the username in the wrong place. Inside of $data is first the name Appin, Lucinda, etc…
So, to fix this, either alter the $data array to hold username, password and whatever Appin is as you also call this the username.
Well, first you need to sort out what all of these are and how you are using them.
Normally, you use the username and password to read from the posted form.
This is sent to a form based on the identity of the user. I would suggest a few changes.
First, a data array such as your $data is a table. It should be simple. You have it as an array of arrays.
Therefore, you have to use the first level before the second array can be reached.
Also, you test it in one line and do not parse thru the array to validate the passwords.
So, let’s first talk about the names you selected for the variables. In the form, you use “username” and
“password”. Which is fine. But, you should name the user item that is the “Appin” as something else
such as “userid” or something you like. This makes it easier to understand the difference.
Now, if you leave your data structure the same, you need to first test to see of the username exists INSIDE of each of the arrays. Since the first level of your arrays are the userid, not the name, you can not do it the way your are trying to. If you reverse the order and place the username where the userid is, you can check the first level for the user name. but since you are new to PHP, let’s walk thru all the steps needed…
Create a page that has the entry fields for username and password in it.
This form points the posting to a second form or to itself. Since you didn’t show the posting form, I will just assume it is correct. Once the user presses the submit button the validation code starts.
In this section, the first this is to check if the user names and passwords are valid. This is usually done with a database lookup and takes less work to validate. In your case you are using a table. You have decide to use the userid and not the username as the base value. So perhaps you could use the username instead and use the password and the redirect page as the values. (Since in the second example, you show the page being redirected to separate pages.) You could place the “appin_mine.php” etc into the table. This would make it easier to do the redirect as you can pull the page from the table.
Then, in the validation, you would test if the $_POST[“username”] exists in the table first.
My name is Ernie. If I enter that, it should give an error and not even bother checking for my password.
So, you can do something like if(in_array($_POST[“username”], $data){this name exists}
Then inside that code if it exists, check if the $_POST[“password”] matches the inside value.
Well, that is a start… Try it out and repost your newer version. Good luck…