I am creating a login application using PHP/Phpmyadmin and I am having an issue. I found another program online and I am mimicking its function, but I am unable to get it to work. Basically I have a database named ‘vendors’ with a table called ‘users’. I want the login app to pull the username and password from my database and approve/reject depending on if the user is found. I have been working on this for some time and have not been able to figure it out. Any help is much appreciated.
Sorry about that. I am not getting an error message, I am trying to get help/suggestions with the functionality of the application. I am a newb to coding and could use some help to finishing my application. I appreciate your last suggestion. It made sense. I will update that identifier. Thanks
Can you expand on this? What does it not do that it should, or what does it do that it should not?
As @Gandalf said, you should have your processing code before the form is displayed - when the user presses “submit” on your form, it will re-draw the form before it tries to process the login information that the user has provided. Because stuff (your HTML) has already been sent to the browser, your header() relocate on successful login will not work, and you should see a “headers already sent” error message.
But if that’s not the problem, can you add some detail about the issue please?
My understanding is the problem isn’t so much “this mostly works except for this” but more “how do I put this together”.
What I find helpful for me is to start with a rough outline of what would be involved. eg.
need HTML form
need database tables to hold input values
what values do I need?
username
password
security!!
other? any unique?
new vs. returning
display form
check against existing database values
do stuff
As can be seen, it is very rough and incomplete. It serves only to help me get a “feel” for things. How to proceed and finer details (ie. the “other” and “stuff”) will vary and depends on what is needed and developer preference.
For example, some may prefer to write more OOP-ish code, others more procedural. Some may prefer to display the form again with the submitted values and ask for confirmation, others to go to a “success” page straight away.
More often than not, while working up the code other things come to mind and I revise the rough outline. eg. What do I do when there is a form error? What do I want to do to help prevent attacks? How can I ensure the form is accessible?
I find it easier to start simple and add complexity after making sure the simple works. A cycle of add until it breaks, fix, rinse repeat.
I think it could be helpful for you to put aside your example code for a while and put together a “minimal skeleton”. That is, write a very simple form with a single input, skip the database and SESSION stuff for now, and just have the code do one thing when the page first loads and another when the form has been submitted.
in lines 16 and 20 you are submitting the values for the inputs named “username” and “password” respectively.
In lines 30 and 31 you are retrieving the variables “user” and “pass”… Notice something?
Given what has been said about reserved words I would change the input names to match the names used in 30/31.