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}

Recommended Answers

All 3 Replies

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'

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.