You can set in the database that the column 'board' is of the type UNIQUE, which will not allow duplicate data or you can create on your page a SELECT that checks if the board already exists. If it exists it returns an error message, otherwise it performs INSERT.
To do SELECT you can:
1 - SELECT * FROM vehicles WHERE plate = $plate
2 - SELECT plate from vehicles WHERE plate = $plate
Difference: in the first option you search all vehicle information, so if you want more data to compare you can use this, if you don’t need it, you can use the below.
Your code would look like this:
$query = "SELECT * FROM veiculos WHERE placa = $placa";
$result = mysqli_query($conn,$query); //Faz select para consultar as placas
if(mysql_num_rows($result) > 0) //checa se a consulta teve alguma linha {
$query = "INSERT INTO veiculos (placa, cidade, estado)
VALUES('$placa','$cidade','$estado')";
$result = mysqli_query($conn,$query);
} else {
echo "Erro";
}
how would this select?
– Diogo Carvalho
@Diogocarvalho added in the reply
– Leticia Rosa
this error appears. Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, Boolean Given in
– Diogo Carvalho
Make a test to see what it is returning. Apparently it returns false, IE, did not work your query. Replace > 0 with == false and invert what it would do (if it appears false it gives an error echo, otherwise it does the other query.
– Leticia Rosa