as valid that there are no duplicate records?

1

I need to avoid the duplication of records in my database, specifically in my table usuario taking into account the field id_Funcionario belonging to the table.

This is the form:

registro.php

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Consultas</title>
        <link rel="stylesheet" type="text/css" href="estilos.css">
    </head>
    <body>
        <center>
       <h1>Formulario Registro</h1>
       <form action="registrar.php" method="post" class="form-register">
        <h2 class="form__titulo">Registrar funcionario</h2>
        <div class="contenedor-inputs"></div>
        <input type="text" REQUIRED name="id_Funcionario" placeholder="Cedula" class="input-48">
        <input type="text" REQUIRED name="primer_Nombre" placeholder="Primer Nombre" class="input-48">
        <input type="text" REQUIRED name="segundo_Nombre" placeholder="Segundo Nombre" class="input-48">
        <input type="text" REQUIRED name="primer_Apellido" placeholder="Primer Apellido" class="input-48">
        <input type="text" REQUIRED name="segundo_Apellido" placeholder="Segundo Apellido" class="input-48">
        <input type="text" REQUIRED name="cargo_Funcionario" placeholder="Cargo Funcionario" class="input-48">
        <input type="text" REQUIRED name="telefono_Funcionario" placeholder="Telefono Funcionario" class="input-100">
        <input type="text" REQUIRED name="edad_Funcionario" placeholder="Edad Funcionario">
        <input type="text" REQUIRED name="sexo_Funcionario" placeholder="Sexo"></br>
        <br><input type="submit" value="Registrar" class="btn-enviar">
        <input type="button" value="Volver!" onclick="history.back(-1)" style="margin-left: 3%" /></br> 
        </center>
      </form>     
    </body>
</html>

And here is the insertion in the database:

register.php

<?php 

$conexion =  mysqli_connect("localhost", "root","admin123","database");

$id_Funcionario = $_POST["id_Funcionario"];
$primer_Nombre = $_POST["primer_Nombre"];
$segundo_Nombre = $_POST["segundo_Nombre"];
$primer_Apellido = $_POST["primer_Apellido"];
$segundo_Apellido = $_POST["segundo_Apellido"];
$cargo_Funcionario = $_POST["cargo_Funcionario"];
$telefono_Funcionario = $_POST["telefono_Funcionario"];
$edad_Funcionario = $_POST["edad_Funcionario"];
$sexo_Funcionario = $_POST["sexo_Funcionario"];


$insertar = "INSERT INTO usuario (id_Funcionario, primer_Nombre, segundo_Nombre, primer_Apellido, segundo_Apellido, cargo_Funcionario, telefono_Funcionario, edad_Funcionario, sexo_Funcionario) VALUES( '".$id_Funcionario."',                 '".$primer_Nombre."','".$segundo_Nombre."','".$primer_Apellido."','".$segundo_Apellido."','".$cargo_Funcionario."',
'".$telefono_Funcionario."','".$edad_Funcionario."','".$sexo_Funcionario."')";


$resultado = mysqli_query($conexion,$insertar);
if (!$resultado) {

    header("location:MostrarRegistros.php");

}else{
    echo '<script>
    alert("El funcionario fue registrado");
    </script>';

}


?>

         

    
asked by Cristian Antonio Trujillo Gris 22.03.2018 в 16:34
source

1 answer

2

make your official_id the Primary Key in your database and the database itself will not allow you to have two records with the same official_id

To make your column a primary key you have to do something similar to this in your database

ALTER TABLE base_de_datos.tabla ADD PRIMARY KEY (columna);//columna = id_Funcionario
    
answered by 22.03.2018 в 16:45