CONSULTA SOBRE INSERTAR UN ID GENERADO
Publicado por Luis Alberto (2 intervenciones) el 04/07/2019 23:05:38
Hola a todos,
Es un gusto estar en una red de gente experta programando, estoy estancado en un problema y quisiera que por favor me den la mano con ello, les comento, estoy intentando desde un formulario ingresar valores para 2 tablas, las dos tablas tienen el ID auto increment, la idea es generar el ID de un pedido insertando un valor para luego tomar ese ID e insertarlo en la siguiente tabla
Agradezco mucho su atención y amabilidad, espero puedan ayudarme para seguir avanzando, gracias!!!!
Es un gusto estar en una red de gente experta programando, estoy estancado en un problema y quisiera que por favor me den la mano con ello, les comento, estoy intentando desde un formulario ingresar valores para 2 tablas, las dos tablas tienen el ID auto increment, la idea es generar el ID de un pedido insertando un valor para luego tomar ese ID e insertarlo en la siguiente tabla
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/// DATOS QUE SE VAN A INSERTAR EN LA TABLA PEDIDO
$usuario = $_SESSION['iduser'];
$fecha = date("Y-m-d");
// INSERCIÓN EN LA TABLA PEDIDO
$sql3 = "INSERT INTO pedido (id_user, fechaEnvio, estado)
values ('".$usuario."','".$fecha."', 1)";
$sqlRes=$conexion->query($sql3) or mysql_error();
//// SE GENERA EL ID PERO NO SE COMO TOMAR ESE VALOR PARA PASARLO AL SIGUIENTE INSERT YA QUE ESTE INSERTA VALORES CON UN ARRAY
/// DATOS QUE VAN A INSERTAR EN LA TABLA SOLICITUD
$items1 = ($_POST['articulo']);
$items2 = ($_POST['nombre']);
$items3 = ($_POST['estado']);
$items4 = ($_POST['fecha']);
///////////// SEPARAR VALORES DE ARRAYS, EN ESTE CASO SON 4 ARRAYS UNO POR CADA INPUT
while(true) {
//// RECUPERAR LOS VALORES DE LOS ARREGLOS ////////
$item1 = current($items1);
$item2 = current($items2);
$item3 = current($items3);
$item4 = current($items4);
////// ASIGNARLOS A VARIABLES ///////////////////
$art=(( $item1 !== false) ? $item1 : ", ");
$descp=(( $item2 !== false) ? $item2 : ", ");
$est=(( $item3 !== false) ? $item3 : ", ");
$fecha=(( $item4 !== false) ? $item4 : ", ");
//// CONCATENAR LOS VALORES EN ORDEN PARA SU FUTURA INSERCIÓN ////////
$valores='('.$art.',"'.$descp.'","'.$est.'","'.$fecha.'"),';
//////// YA QUE TERMINA CON COMA CADA FILA, SE RESTA CON LA FUNCIÓN SUBSTR EN LA ULTIMA FILA /////////////////////
$valoresQ= substr($valores, 0, -1);
///////// 2 QUERY DE INSERCIÓN ////////////////////////////
$sql = "INSERT INTO solicitud (id_pedido, id_articulo,descripcion, estado,fecha)
VALUES $valoresQ";
///// COMO PODRAN OBSERVAR EN EL ID_PEDIDO ES DONDE QUIERO INSERTAR EL VALOR PERO NO SE COMO
$sqlRes=$conexion->query($sql) or mysql_error();
// Up! Next Value
$item1 = next( $items1 );
$item2 = next( $items2 );
$item3 = next( $items3 );
$item4 = next( $items4 );
$item4 = next( $items4 );
// Check terminator
if($item1 === false && $item2 === false && $item3 === false && $item4 === false ) break;
}
Agradezco mucho su atención y amabilidad, espero puedan ayudarme para seguir avanzando, gracias!!!!
Valora esta pregunta


0