Foros del Web » Programando para Internet » PHP »

guardar datos pedido de formulario a mysql y consultarlos

Estas en el tema de guardar datos pedido de formulario a mysql y consultarlos en el foro de PHP en Foros del Web. estimados tengo un formulario de pedidos: Código PHP: <?php require( "../mod_configuracion/conexion.php" ); require( "../theme/header_inicio2.php" ); ?> <script type="text/javascript"> function MM_validateForm() { //v4.0   if (document.getElementById){     var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;     for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);       if (val) { nm=val.name; if ((val=val.value)!="") {         if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');           if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';         } else if (test!='R') { num = parseFloat(val); ...
  #1 (permalink)  
Antiguo 15/01/2014, 13:28
 
Fecha de Ingreso: mayo-2013
Mensajes: 21
Antigüedad: 13 años, 5 meses
Puntos: 0
guardar datos pedido de formulario a mysql y consultarlos

estimados tengo un formulario de pedidos:

Código PHP:
<?php
require("../mod_configuracion/conexion.php");
require(
"../theme/header_inicio2.php");?>
<script type="text/javascript">
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
</script>

<br />
<div class="titulo">Solicitud despacho Alimentos</div><br /><br />

<form action="pagPedido.php" onkeypress="if (event.keyCode == 13) event.returnValue = false;" method="post">
  <table width="100%">

          <tr>
            <td><table align="center">
                <tr>
                <td class="tdatos"> Fecha Solicitud </td>
                <td> <input type="text" name="dia" value="<?php echo date('d'); ?>" readonly size="1" />/<input type="text" name="mes" value="<?php echo date('m'); ?>" readonly size="1" />/<input size="10" type="text" name="ano" value="<?php echo date('Y'); ?>" readonly /></td>
                
                </tr>
                
                
                
                <tr>
                  <td class="tdatos">RUT Empresa:</td>

                  <td><input name="Nombre" type="text" id="Nombre" value="<?php echo "".$_SESSION["login"]. ""; ?>"tabindex="1" readonly="readonly"/></td>
                </tr>
                <tr>
                  <td class="tdatos">Nombre Empresa:</td>
                  <td><input name="Apellido" type="text" value="<?php echo "".$_SESSION["nombre"]. ""; ?>" id="Apellido" tabindex="2" readonly="readonly"/></td>
                </tr>
                 <tr>
                  <td class="tdatos">Mail Contacto:</td>
                  <td><span id="sprytextfield1">
                    <label>

                      <input name="Mail" type="text" id="Mail" tabindex="3" size="40"/>
                    </label>
                    <span class="textfieldRequiredMsg">*</span></span>
              
          </tr>
          
                           <tr>
                  <td class="tdatos">Direcci&oacute;n Despacho (incluya comuna):</td>
                  <td><span id="sprytextfield1">
                    <label>

                      <input readonly="readonly" name="direccion" type="text" id="direccion" value="<?php echo "".$_SESSION["direccion"]. ""; ?>" tabindex="4" size="50"/>
                    </label>
                    <span class="textfieldRequiredMsg"></span></span>
              
          </tr>
          
                           <tr>
                  <td class="tdatos">Comuna:</td>
                  <td><span id="sprytextfield1">
                    <label>

                      <input readonly="readonly" name="comuna" type="text" id="comuna" value="<?php echo "".$_SESSION["comuna"]. ""; ?>" tabindex="5" size="30"/>
                    </label>
                    <span class="textfieldRequiredMsg"></span></span>
              
          </tr>
                           <tr>
                  <td class="tdatos">Telefono:</td>
                  <td><span id="sprytextfield1">
                    <label>

                      <input readonly="readonly" name="fono" type="text" id="fono" value="<?php echo "".$_SESSION["fono"]. ""; ?>" tabindex="6" size="30"/>
                    </label>
                    <span class="textfieldRequiredMsg"></span></span>
              
          </tr>
          <tr>
            <td class="" colspan="2" ><table width="600px" align="center">
                <tr>
                  <td class="tdatos" width="25%">Elija Marca a comprar:</td>

                  <td class=""><span id="elegir_producto" >
                    <select name="producto_select" id="producto_select" onchange="elegir_producto_aceptar()"  tabindex="12">
                        <option value="elegir">Elegir un Producto</option>
                      <option value="Eprueba">Eprueba</option>                      <option value="p">prueba</option>
                      <option value="sp">Sp </option>           
                    </select>
                    </span></td>
                </tr>
                <tr>
                  <td class="tdatos">Elija un Art&iacute;culo:</td>
                  <td><div id="codigo_elegir">

                      <select name="subproducto_select" id="subproducto_select"  tabindex="13">
                        <option value="elegir">Elegir</option>
                      </select>
                    </div></td>
                </tr>
                <tr>
                  <td class="tdatos">Cantidad:</td>
                  <td><input name="producto_cantidad" type="text" size="1px" id="producto_cantidad" tabindex="14"/></td>

                </tr>
              </table>
              <div align="center">
                <input onkeypress="if (event.keyCode == 13) event.returnValue = agregar_producto_aceptar();" type="button" value="Agregar a la lista" onClick="agregar_producto_aceptar()"  tabindex="15"/>
              </div></td>
          </tr>
          <tr>
            <td class="tdatos" height="59" colspan="2" align="left" id="" name="lista_productos_pedidos",><center>
              Revise su pedido aquí abajo
            </center></td>
          </tr>

          <tr>
            <td colspan="2" align="center"><strong>LISTA DE PRODUCTOS</strong></td>
          </tr>
          <tr>
            <td colspan="2" align="center"><span id="productos_comprados"></span></td>
          </tr>
          <tr>
            <td class="tdatos" colspan="2" align="center"><strong>COMENTARIO / ACLARACI&Oacute;N</strong></td>

          </tr>
          <tr>
            <td colspan="2" align="center">
              <textarea name="Comentario" cols="70" rows="4" id="Comentario" tabindex="16" input="input"></textarea>
                </td>
          </tr>
          <tr><center>
             <td colspan="2" align="center"><input name="input" type="submit" tabindex="17" onclick="MM_validateForm('Nombre','','R','Apellido','','R','Mail','','RisEmail');return document.MM_returnValue" value="Enviar Pedido"/>  </td> 
                  
            </center>
          </tr>
        </table>
</form></td>

</table>

<?php
require("../theme/footer_inicio.php");
?>
y me gustaría que cuando se envie el formulario quede registrado en una base de esta constitucion:

Código PHP:
--
-- 
Estructura de tabla para la tabla `pedidos`
--

CREATE TABLE IF NOT EXISTS `pedidos` (
  `
id` int(11) NOT NULL AUTO_INCREMENT,
  `
fecha_sol` date NOT NULL,
  `
rut` text NOT NULL,
  `
Nombre_empr` text NOT NULL,
  `
direccion_desp` text NOT NULL,
  `
comuna` text NOT NULL,
  `
telefono` varchar(30) NOT NULL,
  `
productos` text NOT NULL,
  `
comentario` text NOT NULL,
  
PRIMARY KEY (`id`)
) 
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 
  #2 (permalink)  
Antiguo 15/01/2014, 13:29
 
Fecha de Ingreso: mayo-2013
Mensajes: 21
Antigüedad: 13 años, 5 meses
Puntos: 0
Respuesta: guardar datos pedido de formulario a mysql y consultarlos

y el js:

Código PHP:
id = 0;

function 
validar_form_on_submit(form){
    if (
form.mail.value == form.mail2.value)
    {
        
alert ('Los mails son iguales');
        return 
true;
    }
    else
    {
        
alert ('Los mails ingresados deben ser iguales');
        return 
false;
    }
}


 function 
cargar_variables(){
 
    
producto_lista = new Array();
    
producto_medida1 = new Array();
 
    
divProductos = document.getElementById("Productos");
    
divElegirProducto = document.getElementById("elegir_producto");    
    
divElegirColor = document.getElementById("codigo_elegir");    
    
divProductosComprados = document.getElementById("productos_comprados");
 }

function 
agregar_producto()
{
    
document.getElementById("producto_select").selectedIndex=0;
}


function 
elegir_producto_aceptar(){

    var 
producto = document.getElementById("producto_select").value;
    
// SETEA LAS VARIABLES producto_datos
    
producto_datos(producto)

    
// ARMA EL SELECT
    
var select = armar_select(producto_lista, "subproducto_select");
    
divElegirColor.appendChild(select);

}

function 
eliminarOpcion(){
    var 
opcion = this.parentNode;
    
opcion.parentNode.removeChild(opcion);
}

function 
obtenerIndice(){
    
indice = document.getElementById("subproducto_select").selectedIndex;
    
valor = document.getElementById("subproducto_select").options[indice].firstChild.nodeValue;
    return(
valor);
}

function 
obtenerCantidad(){
    
valor = document.getElementById("producto_cantidad").value;
    return(
valor);
}

function 
validar_subproducto(){
   if ((
obtenerIndice()) == "Elegir") {
        
alert("Debe Elegir una variedad de producto");
        return 
false;
   }
   if ((
obtenerCantidad()) == "") {
        
alert("Debe Colocar una cantidad");
        return 
false;
   }
   return 
true;
}

function 
agregar_producto_aceptar(){
    if (
validar_subproducto()) 
    {
        var 
producto_elegido = obtenerIndice();
        var 
producto_cantidad = obtenerCantidad();
        
agregar_lista_producto(producto_elegido, producto_cantidad);
        
document.getElementById("producto_select").selectedIndex = 0;
        
document.getElementById("subproducto_select").selectedIndex = 0;
    }
}

function 
agregar_lista_producto(nombre, cantidad){
    
    var 
nombre_id = "lista_prod";
    
    var 
linea = document.createElement("div");
    
    var 
input = document.createElement("input");
    
input.setAttribute("type", "text");
    
input.setAttribute("id", nombre_id + id);
    
input.setAttribute("name", nombre_id + id);
    
input.setAttribute("size", "75");
    
input.setAttribute("value", nombre + "     |     " + "Cantidad:   " + cantidad);
    
    var 
boton = document.createElement("input");
    
boton.type = "button";
    
boton.value = "Quitar";
    
boton.onclick = eliminarOpcion; 
    
    
linea.appendChild(boton);
    
linea.appendChild(input);
    
divProductosComprados.appendChild(linea);
    
id ++;
    
    
document.getElementById("producto_cantidad").value = "";
}

function 
cerrar(){
    
// document.getElementById("codigo_elegir").style.display = "none";
    // document.getElementById("elegir_producto").style.display = "none";
}



 function 
armar_select(opciones, select_id)
{
    
    
/* VACIA EL SELECT */
    
var select = document.getElementById(select_id);
    while(
select.childNodes[0]){  
        
select.removeChild(select.childNodes[0]);  
    }
    
    
/* SE AGREGA UN OPTION COMODIN */
        
opcion = document.createElement("option");
        
opcion.appendChild(document.createTextNode("Elegir"));
        
select.appendChild(opcion);

    
    
/* SE AGREGA UN OPTION POR CADA ELEMENTO DEL ARREGLO */
    
for (i in opciones){
        
productos = opciones[i];
        
optgroup = document.createElement("optgroup");
        

        for (
o in productos) {
            if (
o == 0){
                
optgroup.setAttribute("label", productos[o]);        
            }
            else
            {
                
opcion = document.createElement("option");
                
opcion.setAttribute("value", document.createTextNode(productos[o]));
                
opcion.appendChild(document.createTextNode(productos[o]));
                
optgroup.appendChild(opcion);
            }
        }
        
select.appendChild(optgroup);
    }
    return 
select
}
 
function 
producto_datos(producto){
    switch (
producto){
    case 
"elegir" :
        var 
lista1 = new Array ();
        
producto_lista = new Array(lista1);
        break;

//// Earthborn Holistic        
case "holistic" :
var 
lista1 = new Array ("PERROS HOLISTIC", "Puppy Vantage 12 KG (EH)", "Puppy Vantage 6 KG (EH)", "Puppy Vantage 2,5 KG (EH)", "Ocean Fusion 12 KG (EH)", "Ocean Fusion 6 KG (EH)", "Ocean Fusion 2,5 KG (EH)","Small Breed 12 KG (EH)", "Small Breed 6 KG (EH)", "Small Breed 2,5 KG (EH)");
var 
lista2 = new Array ("PERROS GRAIN FREE", "Primitive Natural 12 KG (EH)", "Primitive Natural 6 KG (EH)", "Primitive Natural 2,5 KG (EH)", "Coastal Catch 12 KG (EH)", "Coastal Catch 6 KG (EH)", "Coastal Catch 2,5 KG (EH)");
var 
lista3 = new Array ("GATOS HOLISTIC","Feline Vantage");
var 
lista4 = new Array ("GATOS GRAIN FREE", "Primitive Feline", "Wild Sea Catch");
producto_lista = new Array(lista1,lista2,lista3,lista4);
break;


////// PROPAC
case "propac" :
var 
lista1 = new Array ("Perros-Puppy", "Large Breed Puppy 15 KG (PP)", "Large Breed Puppy 20 KG (PP)", "Performance Puppy 3 KG (PP)", "Performance Puppy 8 KG (PP)", "Performance Puppy 15KG (PP)", "Performance Puppy 20 KG (PP)", "Small Breed Puppy 3KG (PP)");
var 
lista2 = new Array ("Perros-Adulto", "Large Breed Adulto 20 KG (PP)", "Large Breed Adulto 15 KG (PP)", "Adult Chunk 3 KG (PP)", "Adult Chunk 15KG (PP)", "Adult Chunk 20 KG (PP)", "Adulto MINI Chunk 3 KG (PP)", "Adulto MINI Chunk 8 G (PP)", "Adulto MINI Chunk 15 KG (PP)", "Small Breed Adulto 3 KG (PP)");
var 
lista3 = new Array ("Gatos", "Kitten Food  3KG (PP)", "Adult Cat 3 KG (PP)", "Adult Cat 7,5KG (PP)");
var 
lista4= new Array ("Especiales", "Sensitive 3KG (PP)", "Sensitive 15 KG (PP)", "High Performance 15 KG (PP)", "Adulto Senior 3KG (PP)", "Adulto Senior 7,5KG (PP)", "Adulto Senior 15KG (PP)", "Large Breed Senior 15 KG (PP)", "Low Fat 3 KG (PP)", "Low Fat 7,5 KG (PP)", "Low Fat 15 KG (PP)");
producto_lista = new Array(lista1,lista2,lista3,lista4);
break;
        
////// SP
    
case "sportmix" :
        var 
lista1 = new Array ("Puppy", "Puppy Food Mini Morsels 20KG (SM)");
        var 
lista2 = new Array ("Adultos", "High Energy 20KG (SM)", "Maitenance 20 KG (SM)", "Large Breed 20 KG (SM)", "High Protein 20 KG (SM)", "Chunk Style 18 KG (SM)");
        var 
lista3 = new Array ("Gatos", "Cat Gourmet 7,5 KG (SM)");
        
producto_lista = new Array(lista1,lista2,lista3);
        break;
        
////// Otros

    
case "otros" :
        var 
lista1 = new Array ("Arena Sanitaria", "PRO CAT 4 KG", "PRO CAT 9 KG");
        var 
lista2 = new Array ("Treats", "Nut'r'Nipz", "Rewards Mini", "Rewards Strip", "Rewards Sticks");
        
producto_lista = new Array(lista1,lista2);
        break;
    }
} 


como lo guardo en la tabla? ojo que pueden ser miles de productos, necesito que se guarden todos y que despues en un query se muestren. Saludos!!!!

Etiquetas: fecha, formulario, mysql, pedido, 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 09:56.