Okay so i have this form that is supposed to fill multiple tables but when i click on the send button, the page just refreshes, and when i check phpmyadmin the tables are empty.
i have a code that is supposed to tell me if the data got succesfully registered in the database, but i cant get it to work either, it doesn't show up at all, not even to tell me the registration was not succesful.
I've been struggling with this code for 3 days, im pretty new to coding but i tried every change i could an i still can't get it to work.
Here's the code:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Registro empleado</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css">
</head>
<body>
<form>
<h1>Ingresar Datos</h1>
<h3>Cliente</h3>
<input type="number" name="id_cliente" placeholder="id_local"><!--ingreso del id-->
<input type="text" name="nombre" placeholder="nombre"><!--ingreso del nombre del cliente-->
<input type="text" name="domicilio" placeholder="domicilio"><!--ingreso del domicilio-->
<input type="text" name="telefono" placeholder="telefono"><!--ingreso del numero de telefono-->
<input type="text" name="edad" placeholder="edad"><!--ingreso de la edad del cliente-->
<h3>Ganancias</h3>
<input type="number" name="id_ganancias" placeholder="id_ganancias"><!--ingreso del id-->
<input type="number" name="diarios1" placeholder="diarios"><!--ingreso de ganancias diarias-->
<input type="number" name="mensuales1" placeholder="mensuales"><!--ingreso de ganancias mensuales-->
<input type="number" name="anuales1" placeholder="anuales"><!--ingreso de ganancias anuales-->
<h3>Gastos</h3>
<input type="number" name="id_gastos" placeholder="id_gastos"><!--ingreso del id-->
<input type="number" name="diarios2" placeholder="diarios"><!--ingreso de gastos diarios-->
<input type="number" name="mensuales2" placeholder="mensuales"><!--ingreso de gastos mensuales-->
<input type="number" name="anuales2" placeholder="anuales"><!--ingreso de gastos anuales-->
<input type="submit" name="enviar"><!--botton de enviar-->
</form>
<form action="http://localhost/consulta_cliente.php"><!--link para phpadmin-->
<input type="submit" value="consulta_cliente"><!--boton que te lleva phpadmin-->
<form action="http://localhost/consulta_ganancias.php"><!--link para phpadmin-->
<input type="submit" value="consulta_ganancias"><!--boton que te lleva phpadmin-->
<form action="http://localhost/consulta_gastos.php"><!--link para phpadmin-->
<input type="submit" value="consulta_gastos"><!--boton que te lleva phpadmin-->
</form>
<?php
include("registrar_empleado.php");/*Llamado a el archivo php de registro*/
?>
</body>
</html>
PHP:
<?php
//Llamada a código de conexión
include("conexion_empleado.php");
//validación de variables que recibirán cada campo de la tabla
//cliente
if (isset($_POST['enviar'])) {
if (strlen($_POST['id_cliente']) >=1 && strlen($_POST['nombre']) >= 1 && strlen($_POST['domicilio']) >= 1 && strlen($_POST['edad']) >= 1 && strlen($_POST['telefono']) >= 1) {
$id_cliente = trim($_POST['id_cliente']);
$nombre = trim($_POST['nombre']);
$domicilio = trim($_POST['domicilio']);
$telefono = trim($_POST['telefono']);
$edad = trim($_POST['edad']);
//inserción de registros en la tabla datos
$consulta1 = "INSERT INTO cliente(id_cliente, nombre, domicilio, telefono, edad) VALUES ('$id_cliente', '$nombre', '$domicilio', '$edad', '$telefono')";
$resultado1 = mysqli_query($conecta,$consulta1);
//ganancias
if (strlen($_POST['id_ganancias']) >=1 && strlen($_POST['diarios1']) >= 1 && strlen($_POST['mensuales1']) >= 1 && strlen($_POST['anuales1']) >= 1) {
$id_ganancias = trim($_POST['id_ganancias']);
$diarios1 = trim($_POST['diarios1']);
$mensuales1 = trim($_POST['mensuales1']);
$anuales1 = trim($_POST['anuales1']);
$consulta2 = "INSERT INTO ganancias(id_ganancias, diarios, mensuales, anuales) VALUES ('$id_ganancias', '$diarios1', '$mensuales1', '$anuales1')";
$resultado2 = mysqli_query($conecta,$consulta2);
//gastos
if (strlen($_POST['id_gastos']) >=1 && strlen($_POST['diarios2']) >= 1 && strlen($_POST['mensuales2']) >= 1 && strlen($_POST['anuales2']) >= 1) {
$id_gastos = trim($_POST['id_gastos']);
$diarios2 = trim($_POST['diarios2']);
$mensuales2 = trim($_POST['mensuales2']);
$anuales2 = trim($_POST['anuales2']);
$consulta3 = "INSERT INTO gastos(id_gastos, diarios, mensuales, anuales) VALUES ('$id_gastos', '$diarios2', '$mensuales2', '$anuales2')";
$resultado3 = mysqli_query($conecta,$consulta3);
if ($resultado1 && $resultado2 && $resultado3) {
?>
<h3 class="completo">Registro exitoso</h3>
<?php
} else {
?>
<h3 class="incompleto">Error de registro</h3>
<?php
}
} else {
?>
<h3 class="incompleto">Por favor completa el registro</h3>
<?php
}
}
}
}
?>
PHP code to connect to the database:
<?php
//código para asignar las variables para la conexión: localhost = nombre servido, usuario = root, nombre_BD = registro
$conecta = mysqli_connect("localhost","root","","locales");
?>
I have some code to show the last rows that were filled by the form, i can't test if it works yet since i can't get data to even get send to the database, anyways here it is just it case:
Query1:
<?php
include("conexion_cliente.php");//Llamado a el documento php
$consulta1_1 = "select * from pago";//se muestra la tabla pago
$resultado1_1 = mysqli_query($conecta,$consulta1_1);
$cuenta = mysqli_num_rows ($resultado);
$cuenta = $cuenta - 1;
$resultado1 = mysqli_query($conecta, "SELECT * FROM cliente LIMIT $cuenta, 1"); //consulta de tabla empleando
//limit para obtener solo una fila
echo "<h1>ULTIMO CAMPO</h1>"; //titulo
echo "<pre>"; //atributo pre para poder realizar el salto de línea
while($row1 = mysqli_fetch_array($resultado1)) { //se obtienen los arrays de la consulta
echo print_r($row1); //se imprimen los resultados de la consulta
echo "\n"; //salto de linea
}
echo "</pre>";
?>
Query2:
<?php
include("conexion_cliente.php");//Llamado a el documento php
$consulta2_1 = "select * from pago";//se muestra la tabla pago
$resultado2_1 = mysqli_query($conecta,$consulta2_1);
$cuenta = mysqli_num_rows ($resultado);
$cuenta = $cuenta - 1;
$resultado2 = mysqli_query($conecta, "SELECT * FROM ganancias LIMIT $cuenta, 1"); //consulta de tabla empleando
//limit para obtener solo una fila
echo "<h1>ULTIMO CAMPO</h1>"; //titulo
echo "<pre>"; //atributo pre para poder realizar el salto de línea
while($row2 = mysqli_fetch_array($resultado2)) { //se obtienen los arrays de la consulta
echo print_r($row2); //se imprimen los resultados de la consulta
echo "\n"; //salto de linea
}
echo "</pre>";
?>
Query3:
<?php
include("conexion_cliente.php");//Llamado a el documento php
$consulta3_1 = "select * from gastos";//se muestra la tabla gastos
$resultado3_1 = mysqli_query($conecta,$consulta3_1);
$cuenta = mysqli_num_rows ($resultado);
$cuenta = $cuenta - 1;
$resultado3 = mysqli_query($conecta, "SELECT * FROM gastos LIMIT $cuenta, 1"); //consulta de tabla empleando
//limit para obtener solo una fila
echo "<h1>ULTIMO CAMPO</h1>"; //titulo
echo "<pre>"; //atributo pre para poder realizar el salto de línea
while($row3 = mysqli_fetch_array($resultado3)) { //se obtienen los arrays de la consulta
echo print_r($row3); //se imprimen los resultados de la consulta
echo "\n"; //salto de linea
}
echo "</pre>";
?>
Sorry it's written in spanish, im from mexico but i noticed that this "us" page was more active than the "es" one. Any help it's greatly appreciated and if you have any language related question i'll be glad to answer.