How to change level access after submitting a form? - php

I have a problem to make a web application where I could input a data of a customer, where user level-1 could input data and then user level-2 could check the data, and then user level-3 could approve the data and save it to database. So in every page I want to keep login with different username and password. So every level user would have their own username and password. And how can I make the application where the data that has been inputted by user level-1 in computer-1 to go to user level-2 in computer-2 for checking without saving the data to database and to user level-3 for approval in computer-3 where they would save the data ?
I'm using php and mysql. Could someone maybe give me a help? please.

you could have a second database for unapproved/unchecked data but that would not be the ideal way to do it, you would be better to do as u_mulder suggested and save to the database and have a separate column in the database table to show the status of the data

Related

save and continue form using php and mysql

anyone here knows how to make a save and continue? I have a multi page form and it have many different parts so I need a save and continue form so they can fill out this form on the other day.
So firstly a user will log in into his/her account and they will see this link,
see image here
Once they will click on it, they will see a multi page form like this,
form image
When the user has filled out these data,
Sample data,
sample data 1
sample data 2
So when the user click save, the data that the user have input will be save so when they will log in back into his/her account the data that has been saved will be displayed in the form.
Saved data,
saved data 1
saved data 2
I have not yet tried any code because I'm new to php and mysql so please help! Thank you so much.
Each time a user selects Next, add the data provided by the user to the relevant row in a database table. In this row, have a status column with status 'Draft' until the user completes the form upon which you change the status to 'Completed'.
Each time a user opens the form, load any data already entered in the past by this user.
You might consider using a column to store information about the latest page of the form used by the user, so the user can resume at that particular page of the form later.
We are not here to provide you with all the code. If you have a problem or question related to a part of the code, feel free to ask though.
Good luck!
When the user clicks on the Next Button, Save the Data into your Mysql DB in a Save Block.
In the Save block user "INSERT" Query to Insert Data to DB.
After that use PHP "header" function to redirect to the same page.

How to deal with user email change

I'm adding an option for my users to change their email, and I'm thinking what is the best way of doing it in a safe and fool-proof manner.. so far I have the following options
1) When user changes the email, system stores in a temporary column in the database and sends an email to the new one, requiring the user to click the link to confirm it and only then, change it (I would need 2 extra fields on my DB - temp_email and email_token)
2) When user changes the email, system would gather data from AccountID and New Email, encrypt it and send it to the new email.. when the user clicks the link, system decrypts it and changes accordingly.
I really like the second option, since it does not require saving extra fields on the database.. so my question is.. which one is a better solution? Or perhaps a third one..
I have two fields in my users table: recovery_hash and recovery_time that are updated when a user changes something. I put in a random hash and the current time.
I then send an email to that person (in your case, to their new address), and in the link is the hash (http://foobar.com/verify/randomHashG03sHere). The user clicks the link and it goes to a verify script on the server - which validates the hash and then checks to see if the current time is within an hour of the recovery_time. If both checks validate, I make the change, which, in your case would be updating the users email field with their new email address - which you could store in a separate table, or even in the same users table as a new_email field.
Since you're anticipating the user wanting to change things, you could just store the new email address in a separate table, such as users_temp.email and then update the users table with that new value after it's been validated.
You could just create another table to deal with temporary e-mail addresses (e-mail + AccountID + token + timestamp (possibly)).
I would highly avoid option 2. Keep all your data local on your server! In case someone breaks your encryption he can mess up your entire database or webservice. Especially credentials or email-addresses should never be outsourced. Option 1 is much more recommended, though the data could also be stored in a different manner.

How to handle unique username in php form

I have a register form that goes through the following steps:
Fill in user information (name,adress,etc.) and username
If user presses the submit button, it is checked if username is already in the database or not
If username is already in use, he must rename username, if not, it is shown what he has entered (name,adress etc.).
He has to confirm the website rules and that his input data is correct. If he presses the confirm button, a row with his details and username will be inserted in the database.
I do not want to insert the row in the database after step 2., because I dont want rows from users in my database that did not confirm the rules. Also I want to keep step 3., so the user can make sure that his data is correct. Unfortunately, at the moment the code cant prevent the unlikely case that two user register at the same time with the same username. How does one prevent this case in general? I know there are a lots of php forms out there who proceed with these 4 steps.
EDIT: Sorry, that I didn't make it clear enough: I am not concerned about double entries in my database, this can be prevented by setting the username field unique. I want to know how can I check in step 2. that the username is not used in the database AND not used by any other user who is currently using the registration form.
Data integrity in a database should be ensured by the database, not by the interface.
This means that if you want UNIQUE usernames you should use the built in UNIQUE index in the database.
That way it is impossible to have two users with the same name, even if they registered at the same time.
UPDATE:
Based on your last edit I would could create a temporary table where you would insert the username in Step 2, supposing it doesn't exist in your users table. That way a user can "lock" a username until they complete registration in Step 4.
Once they reach Step 4 you move the data from the temporary table to the users table.
so here is what you can do but make sure what #chevi said .. alter your table and add unique attribute that username column... that all at backend..
now comes front end
..in the form when user has chosen/entered username you can make a ajax call which checks user entered username in your DB and returns TRUE Or FALSE accordingly you can then n there notify user that hey this user name is already taken also you can restrict user to submit that form

PHP putting a connection open while filling a form

A simple form to take user details but I want that if a user is already registered and if he enters his NAME then that script should search it in database and show his details in the form fields before submitting the form.
If I'm understanding you correctly you want a form where the user starts typing in his username and it will display the rest of his information automatically if his username exists in the database? Well in order to retrieve information from a database on the fly while a user is typing in the information (without refreshing the page) you will have to use Ajax.
But logically why would you want a form to search a database just based on a name and display the rest of that username's information before they have logged in or submitted the form? I think you should retrieve a user's details ONLY after you have verified who they are. Not just by them typing in a name. Maybe I am misunderstanding your question though.

Validating Login / Changing User settings / Php Mysql

my questions are about login, and changing already saved data.
Question 1
Until now I've only saved input in the tables of the database (registration steps), now I need to check if the input (login steps), match what is in database. In fact I have 3 types of users, then I'll have to check 3 kind of tables. Then if the input data matches with one of those 3 tables I will redirect the user to their specific area.
I'm thinking about saving the submitted data $login=$_REQUEST['login']; and $password=$_REQUEST['password']; and compare with the login column in the database. Then if the login matches, I'll compare the password submitted with the one in the row, not in the column. But I don't know how to do this search and comparison, neither what to use. Then if both matches I'll redirect the user. Else I'll send a login error message; I know how to do this already.
Question 2
What if I need to change an already saved user, for example if they change their email address? My changing user's data web page is exactly the same like the registration user web page. Can I load the already saved options and values of registration? Then the user will change whatever is necessary, and then when they submit the new information, they would not create a new row in my table, but just overwrite the old information? How can I do this?
Check this out.
Then if that doesn't help a bit, take a look at this.

Categories