Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/06/2015, 11:50
Yhef
 
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)
?>