Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to validate fields of a php form by Ajax but I have to get the type of that field by mysql because i store the data in mysql. So I should validate my data with java after I get the type of the field (from mysql) or I can send them to Mysql to be validated by Mysql or I should validate my data with php?
Which one is better, faster, more reliable and more secure?
Thanks to whom helped but actually I want to validate any kind of type even the protoype, I mean maybe in future they change the type of a column I don't want to go through the whole codes including client_side code to change the rule of validation for my field.
I want something more intelligent.
Thanks in advance.
Posted
Updated 18-Mar-15 15:00pm
v3
Comments
Mohibur Rashid 18-Mar-15 3:09am    
java? are you using java on your client site?
Saeed.A 18-Mar-15 21:06pm    
I mean javascript.

As a general rule it is best to validate your data (and do anything else you can) on the client side. This will eliminate possible delays in the server round-trip.

This isn't always possible, such as when the data needs to be validated against that in a database - in which case AJAX is likely a better choice than a <form> as it doesn't scrub the data fields on the client side.

Since it's on the client side, you normally use javaScript for this. Your "submit" button (or whatever you use) should go through the validation function which, if the validation passes, can formName.submit()the data or call AJAX.

 
Share this answer
 
Comments
Saeed.A 18-Mar-15 21:02pm    
Thanks
0. You should have known of the database schema, i.e. tables, fields, data types, and their relationships before you start coding.
1. Perform the necessary client-side validation using JavaScript for conditions such as required entry, min length, data type, etc. that will eliminate round trip to server if any of the inputs are found to be invalid. Refer: JavaScript Form Validation[^]
2. Next, do the necessary security related validation on the server-side such as account authentication, cleansing of user inputs, etc. See PHP 5 Form Validation[^]. However, you still have to perform validations on those inputs that passes the client-side validation on the server side as client-side script is clear source and opened to hacking.
3. Finally, on the database part, many measures can be put in place to ensure data integrity, such as primary key, referential integrity, and user-defined rules.
All of them work together to make sure that the application is secure and reliable.
 
Share this answer
 
v2
Comments
Saeed.A 18-Mar-15 21:04pm    
Thanks but I want more, I update the question can u help me with this?
Peter Leow 18-Mar-15 22:18pm    
Can changes be anticipated? Most likely not. If you cannot, then you cannot plan nor provide for them.
Saeed.A 19-Mar-15 0:07am    
I want mysql validation, I mean when I want to update a table or add another row to my table and I fill all the field then run the query, mysql will validate my data then store them so I can't use this for validating user's data instantaneously?(by AJAX and PHP)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900