Register - comparison of existing or non-existent values

Asked

Viewed 32 times

0

I’m doing a PHP registration system (working normal), my problem is the following table has a registration with the name "Test", and I wanted when registering another user with the name "Test" or "test", it was not possible to register, because there is already an equal value in the table.

Someone has a solution?

2 answers

1

Use the method strcasecmp to compare. See:

$var1 = "Teste";
$var2 = "teste";
if (strcasecmp($var1, $var2) == 0) {
    echo '$var1 é igual a $var2 numa comparação sem diferenciar maiúsculas e minúsculas';
}
  • Oops, that method worked perfectly. obr

1

I don’t know what database you are using, but at the time of database creation, in the 'name' field you can set it as Unic, that it will not be possible to register another with the same name.

You can change the already created table as the example:

ALTER TABLE tabela
ADD UNIQUE (coluna);

In this way, the DBMS itself does not allow duplicate value Serts.

  • I don’t particularly like this approach, because the fewer requests in the bank, the better. Although it’s not very expensive, I usually prefer to avoid it, unless it’s a very specific case.

  • but this is not a request, it is a BD protection in putting equal names in, this actually demands the need for more protection or not. In relation to performance will certainly not miss anything.

  • I’m saying requisition for a bank appointment. When the client will make any kind of query, first he should open a connection, etc. This always has a cost, even though q is a minimum cost. I believe that an assessment should be made if there are indeed needs to open a connection or do the treatment on the client’s side. But everyone does what they think is best.

  • 1

    Taking advantage of the question. I am trying to make a login system, type in table ta with the value "Test" and in the field the user puts "test", how do I validate the login with the differences of minute and upper case? Sorry for the ignorance I’m new in the area...

  • @João Create another topic to get better answers

  • @acklay What will be the comparison parameter if you do not consult the database then? You need to check which values already exist in the table and compare with the given values, no comparison parameter is possible.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.