I have a form that after is filled out and submitted the user is redirected to another page where the form is displayed.
The way I'm doing this is by inserting the values to the database first and then pulling them out from the database to display the array in the redirected page.
So that no one else sees other user's information, I am using a unique and encrypted token and storing it in both a SESSION value and in the database; I create this token and assign it to the session variable only if there are no errors in the form. In addition, I'm picking up the insert ID and also storing it as a session value as well.
Before displaying anything the page. where the user is redirected to, it checks for the SESSION token, else the user is redirected to the previous page.
On the next page, when I need to select the values from the database I include in my select query something such as "SELECT * FROM table WHERE (token='SESSION['token'] TOKEN AND form_id='$SESSION['form_id']) LIMIT 1" (Please note that this might not be the right syntax for the query it is just the gist of it).
Now, my questions!
Is this secure enough to prevent anyone from trying to see someone else's information? I'm afraid that with the current method it might be vulnerable to an SQL injection, even though i'm using a prepared mysql statement, which sanitizes all the input.
Or should I use method 2,
Which is to store all the information of the user from the form into the SESSION array and display the values of the session, instead of fetching the values from the database.
Thank you in advance for your time and help.