I have an input in HTML with AJAX which enters a 4-digit code with a button to send to a database in MySQL, until now everything is perfectly inserted, and registered in the database.
Now I have to compare that data that is entered in the input and when I click on the submit button, I compare that data in the input with all the records that the database has, that is, if compared to All the data you have in the database and find one like it send me a message saying that this data is already registered in the MySQL database.
To insert the data I use PHP. Next I put the code that I used to insert these values.
<?php
include('conectar.php');
if (isset($_POST['item']) && !empty($_POST['item'])) {
$con=mysqli_connect($host,$user,$pw,$db);
mysqli_query($con,("INSERT INTO TablaCodigos(item) VALUES ('$_POST[item]')"));
echo "<script> alert('Datos Ingresados correctamente a la base de datos') </script>";
} else {
echo "<script> alert('Error!! No se han podido ingresar datos a la base de datos') </script>";
}
?>