Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2014, 13:28
sebasanmarti
 
Fecha de Ingreso: mayo-2013
Mensajes: 21
Antigüedad: 11 años
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` (
  `
idint(11NOT NULL AUTO_INCREMENT,
  `
fecha_soldate NOT NULL,
  `
ruttext NOT NULL,
  `
Nombre_emprtext NOT NULL,
  `
direccion_desptext NOT NULL,
  `
comunatext NOT NULL,
  `
telefonovarchar(30NOT NULL,
  `
productostext NOT NULL,
  `
comentariotext NOT NULL,
  
PRIMARY KEY (`id`)
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=