Foros del Web » Programando para Internet » PHP »

como insertar datos con procedure

Estas en el tema de como insertar datos con procedure en el foro de PHP en Foros del Web. hola, alguien me puede ayudar con este tema por favor ya que en php soy nvo y no lo entiendo mucho, mi problema es el ...
  #1 (permalink)  
Antiguo 26/06/2015, 11:50
 
Fecha de Ingreso: junio-2015
Mensajes: 3
Antigüedad: 8 años, 10 meses
Puntos: 0
como insertar datos con procedure

hola, alguien me puede ayudar con este tema por favor ya que en php soy nvo y no lo entiendo mucho, mi problema es el siguiente tengo un una tabla en mysql y quiero llenarle datos con php pero con un procedure y no se como hacerlo aca les paso mis codigos
Código PHP:
create table ordenCompra(
IdOrden int auto_increment primary key,
Id_Proveedor int,
fechaPedido date,
fechaPago Varchar(12),
Id_Producto int,
Cantidad int,
precioUnitario float,
PrecioTotal float)


alter table ordenCompra add FOREIGN KEY(Id_ProveedorREFERENCES Proveedor(Id_Proveedor)
alter table ordenCompra add FOREIGN KEY(Id_ProductoREFERENCES Producto(Id_Producto)

 
 
 
DELIMITER //
  
 
create procedure ProcedimientoInsertar()
 (
 
in id_proveedor int,
 
in fechapedido date,
 
in fechapago varchar(12),
 
in Id_producto int,
 
in cantidad int,
 
in precioUnitario float,
 
in precioTotal float
 
)
 
begin 
insert into ordenCompra
(id_Proveedor,fechaPedido,fechaPago,Id_producto,Cantidad,precioUnitario,preciototal
values(id_Proveedor,fechaPedido,fechaPago,Id_Producto,Cantidad,precioUnitario,concat(cantidad*precioUnitario));
end
//

llenando datos manualmente si puedo ejm
CALL ProcedimientoInsertar
(1,now(),'12/04/15',1,15,1.5,null)
CALL ProcedimientoInsertar(1,now(),'12/04/15',1,15,10,null)
CALL ProcedimientoInsertar(1,now(),'12/04/15',1,20,0.2,null

aqui mi cod php
Código PHP:
aqui lleno los datos
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ORDEN DE COMPRA</title>
<link rel="shortcut icon" href="../iconos/cli.ico">

<script type="text/javascript">
function validar(e,modo) { // 1
tecla = (document.all) ? e.keyCode : e.which; // 2
if (tecla==8) return true; // 3
patron = (modo=='letra') ? /[A-Za-zs]/ : /[.-0-1-2-3-4-5-6-7-8-9]/ // 4
te = String.fromCharCode(tecla); // 5
return patron.test(te); // 6
}
</script>
</head>
<body bgcolor="">
<?php
/* include ('../Controlador/Control_usuario.php');*/
?>
<?php
include ('../Vista/menu.php'); 
?>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<center>
<p>
<center style="font-weight: lighter; color: ‪#‎00FF15‬; font-size: xx-large;"><h2 style="font-family: Impact, Haettenschweiler, 'Franklin Gothic Bold', 'Arial Black', sans-serif; font-style: normal; font-weight: lighter;"><span style="text-align: left"> NUEVO PERSONAL</span></h2>
</center> 
<?php
include('../Modelo/Libreria.php');
conectar();
?>
<center><form method="POST" action="../Controlador/generar_orden.php">
<center>
<p>
<label><span style="color: ‪#‎DD0B66‬; font-family: Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New', monospace; font-style: normal; font-weight: bolder; font-size: large;">PROVEEDOR</span><br>
</label>
<select style="width: 298px; height:27px" style="height:27px" name="cboproveedor">
<?php
cargar_datos
("select * from proveedor");
?>
</select> 
<label><span style="color: #DD0B66; font-family: Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New', monospace; font-style: normal; font-weight: bolder; font-size: large;"><br>
FECHA DE PAGO</span><br>
</label>
<input required="required" type="text" size="40" style="height:22px" maxlength="50" placeholder="Ingrese fecha de pago" name="txtfecha" value="">
<label><span style="color: #DD0B66; font-family: Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New', monospace; font-style: normal; font-weight: bolder; font-size: large;"><br>
PRODUCTO</span><br>
</label>
<select style="width: 298px; height:27px" style="height:27px" name="cboproducto">
<?php
cargar_datos_1
("select * from producto");
?>
</select> 
<label><span style="color: #DD0B66; font-family: Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New', monospace; font-style: normal; font-weight: bolder; font-size: large;"><br>
CANTIDAD</span><br>
</label>
<input required="required" type="text" size="40" style="height:22px" maxlength="8" onkeypress="return validar(event,'numero')" placeholder="Ingrese aqui la cantidad" name="txtcantidad" value="">
<label><span style="color: #DD0B66; font-family: Consolas, 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', Monaco, 'Courier New', monospace; font-style: normal; font-weight: bolder; font-size: large;"><br>
PRECIO UNITARIO</span><br>
</label>
<input required="required" type="text" size="40" style="height:22px" maxlength="9" onkeypress="return validar(event,'numero')" maxlength="12" placeholder="Ingrese aqui el telefono" name="txtunitario" value="">

<br>
<br>
<br>
<input type="submit" value="GUARDAR" onClick="mensaje()" class="btn btn-primary btn-lg" style="color:white; background-color: blue" >
<input type="reset" value="LIMPIAR" class="btn btn-primary btn-lg" style="color:red; background-color: white">
<input type="button" value="CANCELAR" class="btn btn-primary btn-lg" style="color:blue; background-color: white" onclick="history.back(-1)">
</body>
</html>
Código PHP:
y aqui registro
<?php
$pro
=$_REQUEST['cboproveedor'];
$fechap=$_REQUEST['txtfecha'];
$prod=$_REQUEST['cboproducto'];
$cant=$_REQUEST['txtcantidad'];
$uni=$_REQUEST['txtunitario'];
$cn mysqli_connect("localhost","root","","dliani");
$rs mysqli_query($cn,"CALL ProcedimientoInsertar('$pro',now(),'$fechap,'$prod','$cant','$uni',null)");
mysqli_close($cn)
?>
  #2 (permalink)  
Antiguo 26/06/2015, 13:29
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: como insertar datos con procedure

$rs = mysqli_query($cn,"CALL ProcedimientoInsertar('$pro',now(),'$fechap,'$prod','$cant','$uni',null)");

A simple vista, te falta una comilla para encerrar $fechap
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: fecha, html, mysql, procedure, registro, select, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:50.