Good, I am trying to insert data from my form, but when I press the submit button it sends me the message of:
"Connection made"
What is the message of my php file of connection , nothing more. The code to insert I have it in another file. This is my code.
The one in my form venta_cliente.php :
<div class="container clear_both padding_fix">
<!--\\\\ container start \\\-->
<form action="php/registrar_cliente.php" method="POST">
<div class="form-group">
<label for="idnom">Nombre:</label>
<input type="text" class="form-control" id="idnom" name="nnombre" REQUIRED placeholder="Ingresar Nombre">
</div>
<div class="form-group">
<label for="idape">Apellidos:</label>
<input type="text" class="form-control" id="idape" name="napellido" REQUIRED placeholder="Ingresar Apellidos">
</div>
<div class="form-group">
<label for="idtdoc">Tipo de Documento:</label>
<select class="form-control" id="idtdoc" name="ntdoc">
<option value="DNI">DNI</option>
<option value="RUC">RUC</option>
</select>
</div>
<div class="form-group">
<label for="iddoc">Documento:</label>
<input type="text" class="form-control" id="iddoc" name="ndoc" REQUIRED placeholder="Numero de Documento">
</div>
<div class="row">
<div class="form-group col-sm-4">
<label for="iddir">Direccion:</label>
<input type="text" class="form-control" id="iddir" name="ndireccion" REQUIRED placeholder="Ingresar Direccion">
</div>
<div class="form-group col-sm-8">
<label for="idtelf">Telf/Movil:</label>
<input type="text" class="form-control" id="idtelf" name="ntelf" REQUIRED placeholder="Ingresar Telf o Movil">
</div>
</div>
<input type="submit" class="btn btn-primary" value="Registrar"></button>
<button type="button" class="btn btn-default">Cancelar</button>
</form>
</div>
<!--\\\\ container end \\\-->
And this is the code of my file to register register_client.php :
<?php
include'conexion.php';
$nombre=$_POST['nnombre'];
$apellido=$_POST['napellido'];
$tipo_doc=$_POST['ntdoc'];
$documento=$_POST['ndoc'];
$direccion=$_POST['ndireccion'];
$telf=$_POST['ntelf'];
if(isset($_POST['submit'])){
$sql = "INSERT INTO cliente (nombre, apellidos, tipo_doc, dni, direccion, telfmovil)
VALUES ('$nombre', '$apellido', '$tipo_doc', '$documento', '$direccion', '$telf')";
if ($conn->query($sql) === TRUE) {
echo "Datos registrados correctamente";
} else {
echo "Ups! Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
And the code of my file conexion.php :
<?php
$servername = "localhost";
$username = "root";
$password = "123";
$dbname = "dbagricola";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if (mysqli_connect_error()) {
die("Conexion a la Base de Dato fallida: " . mysqli_connect_error());
}
echo "Conexion hecha";
?>
The files register_client.php and conexion.php are hosted in a folder called PHP, does that affect to insert the data?
If you know what my mistake is, I would be very grateful to have it seen to correct it.