Verify ID before registering it in BD


I need a little help :(, I am just practicing these queries and I have a problem when verifying the existence of an ID (rut) before registering it in my database ... but the filter does not work: [

This is my code:

$votador = $_POST['rut'];

$sql = "SELECT * FROM votante WHERE rut = '$votador'";
$result = $conn->query($sql);

if ($result->num_rows >= 1) {

  echo "El rut ya existe.";


  $sql = "INSERT INTO votante VALUES (NULL,'".$_POST['rut']."')";

  $result = mysql_query($sql);

  if (! $result){

    echo "La consulta SQL contiene errores.".mysql_error();



      header('Location: votaciones.php');
asked by theorpat 08.11.2018 в 21:40

0 answers