No ejecutar un insert si el campo esta vacio
Publicado por David (9 intervenciones) el 28/12/2017 20:40:07
BUeno, el titulo no es muy claro, asiq ue me explicare lo mejor posible por aqui, tengo el siguiente codigo:
codigo HTML
y este codigo php:
todo funciona pero mi pregunta es, ¿es posible que si en la tabla dejo el input vacio, el codigo php que hace el insert no se ejecute, y si es posible como lo hago, si me logran entender jaja les doy gracias.
codigo HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<table border="5px" align="center" class="tb">
<tr>
<td>LINEA</td>
<td>MESA</td>
<td>CANASTILLAS DISPONIBLES</td>
<td>CANASTILLAS ASIGNADAS</td>
<td>HORA DE INICIO</td>
<td>HORA DE FINALIZACION</td>
</tr>
<tr>
<td> <input list="filas" name="fila1" placeholder="seleccione fila"> </td>
<td> <input type="text" name="mesa1" placeholder="seleccione mesa"> </td>
<td> <input type=t ext name=valor1 id=uno></td>
<td> <input type=t ext name=valor2 id=dos></td>
<td> <input type="time" name="hing1"> </td>
<td> <input type="time" name="hpro1"> </td>
</tr>
<tr>
<td> <input list="filas" name="fila2" placeholder="..."> </td>
<td> <input type="text" name="mesa2" placeholder="..."> </td>
<td> <input type=text name=valor3 id=tres min="0"></td>
<td> <input type=text name=valor4 id=cuatro></td>
<td> <input type="time" name="hing2"> </td>
<td> <input type="time" name="hpro2"> </td>
</tr>
<tr>
<td> <input list="filas" name="fila3" placeholder="..."> </td>
<td> <input type="text" name="mesa3" placeholder="..."> </td>
<td> <input type=text name=valor5 id=cinco min="0"></td>
<td> <input type=text name=valor6 id="seis"></td>
<td> <input type="time" name="hing3"> </td>
<td> <input type="time" name="hpro3"> </td>
<tr>
<td></td>
<td>Canastillas faltantes: </td>
<td> <input type=text name=valor7 id=siete min="0"></td>
</tr>
y este codigo php:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$fechae = $_POST["fechae"];
$fruta = $_POST["fruta"];
$prove = $_POST["prove"];
//Estas son las variables para la tabla del patinador
$fila1 = $_POST["fila1"];
$fila2 = $_POST["fila2"];
$fila3 = $_POST["fila3"];
$mesa1 = $_POST["mesa1"];
$mesa2 = $_POST["mesa2"];
$mesa3 = $_POST["mesa3"];
$disp1 = $_POST["valor1"];
$disp2 = $_POST["valor3"];
$disp3 = $_POST["valor5"];
$qued1 = $_POST["valor2"];
$qued2 = $_POST["valor4"];
$qued3 = $_POST["valor6"];
$hing1 = $_POST["hing1"];
$hing2 = $_POST["hing2"];
$hing3 = $_POST["hing3"];
$hpro1 = $_POST["hpro1"];
$hpro2 = $_POST["hpro2"];
$hpro3 = $_POST["hpro3"];
// Codigo para insertar en la tabla patinador
$insertar = mysqli_query($mysqli,"INSERT INTO patinador (FECHA_PROCESO,FECHA_ENTRADA_FRUTA,FRUTA,CODIGO_PROVEEDOR,HORA_PROCESOI,HORA_PROCESOF) VALUES (now(),'$fechae','$fruta','$prove','$hing1','$hpro1')");
if (!$insertar){echo "Error al guardar";}else{echo "Guardado con exito";}
// Codigo sql para insertar datos de la tabla manejo
$insertarr = mysqli_query($mysqli,"INSERT INTO manejo (FECHA_PROCESO,LINEA,MESA,CANASTILLAS_DISPONIBLES,CANASTILLAS_RESTANTES,HORA_PROCESOI,HORA_PROCESOF) VALUES (now(),'$fila1','$mesa1','$disp1','$qued1','$hing1','$hpro1')");
if (!$insertarr){echo "Error al guardar";}else{echo "";}
$insertarr = mysqli_query($mysqli,"INSERT INTO manejo (FECHA_PROCESO,LINEA,MESA,CANASTILLAS_DISPONIBLES,CANASTILLAS_RESTANTES,HORA_PROCESOI,HORA_PROCESOF) VALUES (now(),'$fila2','$mesa2','$disp2','$qued2','$hing2','$hpro2')");
if (!$insertarr){echo "Error al guardar";}else{echo "";}
$insertarr = mysqli_query($mysqli,"INSERT INTO manejo (FECHA_PROCESO,LINEA,MESA,CANASTILLAS_DISPONIBLES,CANASTILLAS_RESTANTES,HORA_PROCESOI,HORA_PROCESOF) VALUES (now(),'$fila3','$mesa3','$disp3','$qued3','$hing3','$hpro3')");
if (!$insertarr){echo "Error al guardar";}else{echo "";}
$borrar = mysqli_query($mysqli,"DELETE FROM `validar` WHERE 1");
if (!$borrar){echo "no borro";}else{echo "";}
?>
todo funciona pero mi pregunta es, ¿es posible que si en la tabla dejo el input vacio, el codigo php que hace el insert no se ejecute, y si es posible como lo hago, si me logran entender jaja les doy gracias.
Valora esta pregunta


0