This will prevent the browser from trying to resubmit the form data should that page get refreshed or browsed away from and back to. You would perform a redirect to the exact same url of the current page to cause a get request for that page. For all other query error numbers, just rethrow the exception and let php handle it.Īfter using the submitted form data, if there are no errors, the data was successfully updated. If there is more than one column that is defined as a unique index, you would build and execute a SELECT query to find which columns contain duplicate values, and you would setup user/validation error message(s) (add it(them) to the array holding the user/validation errors) letting the user know what was wrong with the data that they submitted. If it did, and there is a single column that is defined as a unique index, you know the duplicate value was in that column, and you would setup a user/validation error message (add it to the array holding the user/validation errors) letting the user know what was wrong with the data that they submitted. Since this activity could result in duplicate values for database columns that must be unique, such as the username, email address, …, you would test in the exception error handling for the UPDATE query if a unique index error (number) occurred. After the end of the validation logic, if there are no user/validation errors, use the submitted, trimmed, form data.Īs stated in your previous thread, the UPDATE query would be a prepared query in order to prevent any sql special characters in a value from being able to break the sql query syntax, which is how sql injection is accomplished. You would then validate all the inputs, storing user/validation errors in an array, using the field name as the main array index. If it has, it would then trim all the input data at once, storing it in the array variable. The post method form processing code would first detect if a post method form has been submitted. You would reference elements in the array variable throughout the rest of the code. At the point of getting the current user data, if the variable is empty, you would query to get the user’s data and store it in the array variable. Inside the post method form processing, you would store a trimmed copy of the post form data in it. You would initialize this variable to an empty array in the initialization code section. The way to detect if the form has never been submitted is to use a working array variable to hold a trimmed copy of the form data. get method business logic - get/produce data needed to display the pageįor the activity you are trying to accomplish, after making sure that the current user is logged in in order to access the page at all, you would query at item #3 in the code to get the current user data, but only if the form has never been submitted.Thank you.The code for any php should be laid out in this general order. If you have questions regarding “Simple User Profile With Update Profile Info Using PHP/MYSQL” feel free to ask by commenting below or visit on our contact page. Sample Screenshots:ĭownload the Full Source Code here. Īfter all the code has been added, you may now test the code by running it to using your desire browser.įor More PHP Projects with Source Code, please visit the link here. For the logout of user action, create “logout.php” file then put the following codes. For registration of user profile information, create “register.php” file then put the following codes. Update the “ index.php” file by putting the following codes. For the user’s profile, create and update “ profile.php” file then put the following codes. And Make sure to Create a “connection.php” file to hold the database connection to our PHP project. A link will be seen and view on the link above. Make sure you are done doing in the login and registration. CREATE TABLE `users` ( `user_id` int(11) NOT NULL,
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |