I have a csv file which the contents will be stored in a table but before that I want to validate first the contents of the csv file and the table where it will be stored so that it will not trigger a mysql error during uploading process. Any idea on how can this be done? Thanks
you can't check before upload, before upload you have nothing to check with.
If you have unique table indexes defined on the DB table that will determine if a record is a duplicate, then you can let your SQL handle it by doing an INSERT...ON DUPLICATE KEY UPDATE query.
if you were to read a line from your file and check the value you don't want to duplicate, then you could just run one extra query to see if that value already exists in the db before you create any new records.