0

Hi,

I have a webform where users insert their personal data into db. What I want to do is to prevent duplication in PHP code. Currently I'm using query below but some users do deliberete things to go through this validation like swoping name&surname etc.

I know that if the user realy want to bypass this validation they can do it but I just want to make things hard for them.

Note: Table below has many other fields in it as well as timestamp.

Thanks in advance

SELECT COUNT(*)
FROM users
WHERE
FirstName = UPPER('$textFirstname') AND
LastName = UPPER('$textLastname') AND
DOB = STR_TO_DATE('$textDoB', '%d/%m/%Y') AND
Nationality = '$selectNationality'

if (count > 0) { exit; }
} else { INSERT INTO users}
4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by pritaeas
0

It really depends how far you want to go with checking for duplicatiomn but if you want to make sure they aren't swapping firstname and last name, you could use this

SELECT COUNT(*)
FROM users
WHERE
((FirstName = UPPER('$textFirstname') AND
LastName = UPPER('$textLastname')) OR (FirstName = UPPER('$textLastname') AND
LastName = UPPER('$textFirstname'))) AND
DOB = STR_TO_DATE('$textDoB', '%d/%m/%Y') AND
Nationality = '$selectNationality'
0

Hi,

You can add a new field in your table that concatenate FirstName, LastName, DOB and Nationality and then you can do your request like this :

SELECT COUNT(*)
FROM users
WHERE verif_field = data_to_verify
0

Instead of doing a query, you could add a unique key over those columns. It will have the same effect: the insert will fail, returning false.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.