the registration from an html form to my database is a success but now I find the problem that I have left pending because I can not solve to send a message that the registration already exists, try some things but not I find ...
.php code to insert into the table
<?php session_start();
if(isset($_SESSION['Usuario'])){?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="css/estilo4.css" type="text/css" media="all">
<title>Confirmación</title>
</head>
<body>
<div id=header>
<img src="images/logocfe.png" width="200" height="100" alt="Logo CFE" />
<table width="1339" class="barra" height="30" border="0" bgcolor="#336633">
<td></td>
</table>
</div>
<div>
<?php
$direccion_ip=$_POST['direccion_ip'];
$mascara_de_subred=$_POST['mascara_de_subred'];
$ocupada_por=$_POST['ocupada_por'];
$nodo=$_POST['nodo'];
$switch_panel=$_POST['switch_panel'];
$idDpto=$_POST['idDpto'];
?>
<div class="menu" id=registro>
<center><h1>Datos de Registro dados de Alta</h1>
Dirección IP: <?php echo $direccion_ip; ?><br>
Máscara de Subred: <?php echo $mascara_de_subred; ?><br>
Ocupada por: <?php echo $ocupada_por; ?><br>
Nodo: <?php echo $nodo; ?><br>
Switch/Panel: <?php echo $switch_panel; ?><br>
Departamento: <?php echo $idDpto; ?><br>
</center>
</div>
<?php
$direccion_ip=$_POST['direccion_ip'];
$mascara_de_subred=$_POST['mascara_de_subred'];
$ocupada_por=$_POST['ocupada_por'];
$nodo=$_POST['nodo'];
$switch_panel=$_POST['switch_panel'];
$idDpto=$_POST['idDpto'];
include('libreria2.php');
$insert = "INSERT INTO ips (direccion_ip, mascara_de_subred, ocupada_por, nodo, switch_panel, idDpto) VALUES ('$direccion_ip', '$mascara_de_subred', '$ocupada_por', '$nodo', '$switch_panel', '$idDpto')";
conectar_bd($insert) ;
echo "<center><br>Dirección IP dada de alta corectamente<br></center>";
?>
</div>
<center><a id="submit" href='altaip.php'>Registrar otra Dirección IP</a><br></center>
<center><a id="submit" href='menu.php'>Volver al menú</a><br></center>
</body>
</html>
<?php
}else{
echo 'echo <script> window.location="index.php"; </script>';
}
?>
Both "ip_address" and "node" declare them as unique, so as such, the duplicate record is not reflected in the database, but it does give me the success message on the page
Code of connection to the BD .php
<?php
function conectar_bd($query)
{
$DB_SERVER = "xxx.xxx.com";
$DB_USER = "user";
$DB_DATABASE = "xxx";
$DB_PWD = "123";
$conn=mysqli_connect($DB_SERVER, $DB_USER,$DB_PWD, $DB_DATABASE);
/* check connection */
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n" , mysqli_connect_error());
exit();
}
if ($result=mysqli_query($conn,$query))
echo mysqli_connect_error();
return $result;
}
?>