Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/05/2014, 16:29
juanmandi
 
Fecha de Ingreso: septiembre-2004
Ubicación: Maracay Edo. Aragua
Mensajes: 45
Antigüedad: 19 años, 7 meses
Puntos: 0
Exclamación Faltan datos por llenar...

hola amigos tengo el siguiente problema y no se solucionarlo...

tengo un formulario el cual me registra en una base de datos y es el siguiente....

Código HTML:
Ver original
  1. <input name="codigodelproducto" type="text" id="codigodelproducto" size="20"  align=""<? echo 'value="'.$_POST['codigodelproducto'].'"'; ?> />
  2.                         </div></td>
  3.                         <td height="30" style="text-align: right"><div align="right">Tipo de Producto:</div></td>
  4.                         <td height="30" style="text-align: left"><div align="left">
  5.                           <input name="tipodeproducto" type="text" id="tipodeproducto" size="20"<? echo 'value="'.$_POST['tipodeproducto'].'"'; ?> />
  6.                         </div></td>
  7.                       </tr>
  8.                       <tr>
  9.                         <td height="30" style="text-align: right"><div align="right">Serial:</div></td>
  10.                         <td width="258" height="30"><div align="left">
  11.                           <input name="serial" type="text" id="serial" value="-" size="20"<? echo 'value="'.$_POST['serial'].'"'; ?> />
  12.                         </div></td>
  13.                         <td height="30" style="text-align: right"><div align="right">Marca:</div></td>
  14.                         <td width="377" height="30" style="text-align: left"><div align="left">
  15.                           <input name="marca" type="text" id="marca" size="20"  align="" <? echo 'value="'.$_POST['marca'].'"'; ?>/>
  16.                         </div></td>
  17.                       </tr>
  18.                       <tr>
  19.                         <td height="30" style="text-align: right"><div align="right">Modelo:</div></td>
  20.                         <td height="30"><div align="left">
  21.                           <input name="modelo" type="text" id="modelo" value="-" size="20" <? echo 'value="'.$_POST['modelo'].'"'; ?>/>
  22.                         </div></td>
  23.                         <td height="30" style="text-align: right"><div align="right">Color:</div></td>
  24.                         <td height="30" style="text-align: left"><div align="left">
  25.                           <input name="color" type="text" id="color" value="-" size="20" <? echo 'value="'.$_POST['color'].'"'; ?>/>
  26.                         </div></td>
  27.                       </tr>
  28.                       <tr>
  29.                         <td height="30" style="text-align: right"><div align="right">Año de Fabricación:</div></td>
  30.                         <td height="30"><div align="left">
  31.                           <input name="anofabricacion" type="text" id="anofabricacion" value="-" size="20" <? echo 'value="'.$_POST['anofabricacion'].'"'; ?>/>
  32.                         </div></td>
  33.                         <td height="30" style="text-align: right"><div align="right">Fabricante:</div></td>
  34.                         <td height="30" style="text-align: left"><div align="left">
  35.                           <input name="fabricante" type="text" id="fabricante" value="-" size="20"<? echo 'value="'.$_POST['fabricante'].'"'; ?> />
  36.                         </div></td>
  37.                       </tr>
  38.                       <tr>
  39.                         <td height="30" style="text-align: right"><div align="right">Dias de Garantia:</div></td>
  40.                         <td height="30"><div align="left">
  41.                           <input name="diasdegarantia" type="text" id="diasdegarantia" value="-" size="20"<? echo 'value="'.$_POST['diasdegarantia'].'"'; ?> />
  42.                         </div></td>
  43.                         <td height="30" style="text-align: right"><div align="right">Proveedor:</div></td>
  44.                         <td height="30" style="text-align: left"><div align="left">
  45.                           <input name="proveedor" type="text" id="proveedor" value="-" size="20" <? echo 'value="'.$_POST['proveedor'].'"'; ?>/>
  46.                         </div></td>
  47.                       </tr>
  48.                       <tr>
  49.                         <td height="30" style="text-align: right"><div align="right">Descripcion Breve:</div></td>
  50.                         <td height="30"><div align="left">
  51.                           <textarea name="descripcionbreve" id="descripcionbreve" cols="30" rows="3"<? echo 'value="'.$_POST['descripcionbreve'].'"'; ?>>-</textarea>
  52.                         </div></td>
  53.                         <td height="30" style="text-align: right"><div align="right">Descripcion Detallada:</div></td>
  54.                         <td height="30" style="text-align: left"><div align="left">
  55.                           <textarea name="descripciondetallada" id="descripciondetallada" cols="40" rows="4"<? echo 'value="'.$_POST['descripciondetallada'].'"'; ?>>-</textarea>
  56.  
  57. CONTINUA....




ESE FORMULARIO VA A UNA PAGINA QUE ES LA QUE ME CONFIRMA Y ME REVISA SI LOS DATOS ESTAN LLENOS O NO.. EL CODIGO ES EL SIGUIENTE.


Código PHP:
Ver original
  1. <?php
  2.  include('.php');
  3. if(isset($_POST['submit'])){
  4.     $query = sprintf("SELECT * FROM productos WHERE codigodelproducto='%s' LIMIT 1",mysql_real_escape_string($_POST['codigodelproducto']));
  5.     $sql = mysql_query($query);
  6.     $row = mysql_fetch_array($sql);
  7.     if($row||empty($_POST['codigodelproducto'])|| empty($_POST['tipodeproducto'])||empty($_POST['serial'])|| empty($_POST['marca'])||empty($_POST['modelo'])|| empty($_POST['color'])|| empty($_POST['anofabricacion'])|| empty($_POST['fabricante'])|| empty($_POST['diasdegarantia'])|| empty($_POST['proveedor'])|| empty($_POST['descripcionbreve'])||empty($_POST['descripciondetallada'])||  empty($_POST['preciocompra'])|| empty($_POST['precioventa'])|| empty($_POST['descuento'])|| empty($_POST['diasdegarantiaotor'])|| empty($_POST['cantidad'])|| empty($_POST['comentarios'])){
  8.    
  9.         # si se deja un campo vacío va a tirar un error.
  10.        $error = '<p style="color: red; text-align: center; font-size: 20pt">¡OCURRIO UN ERROR DURANTE EL REGISTRO!<br>';
  11.         if(empty($_POST['codigodelproducto'])){
  12.             $error .= '"Codigo del Producto" se ha dejado vacío.<br>';
  13.         }
  14.         if(empty($_POST['tipodeproducto'])){
  15.             $error .= '"Tipo del Producto" se ha dejado vacío.<br>';
  16.         }
  17.         if(empty($_POST['marca'])){
  18.             $error .= '"La Marca del Producto" se ha dejado vacío.<br>';
  19.                     }
  20.         if(empty($_POST['color'])){
  21.             $error .= '"Color" se ha dejado vacío.<br>';
  22.                     }
  23.         if(empty($_POST['proveedor'])){
  24.             $error .= '"Proveedor" se ha dejado vacío.<br>';
  25.                     }
  26.         if(empty($_POST['preciodeventa'])){
  27.             $error .= '"El precio de Venta" se ha dejado vacío.<br>';
  28.                     }
  29.         if(empty($_POST['cantidad'])){
  30.             $error .= '"Telefono" se ha dejado vacío.<br>';    
  31.         }
  32.         if(empty($_POST['comentarios'])){
  33.             $error .= '"Cantidad" se ha dejado vacío.<br>';  
  34.         }
  35.         if($row){
  36.             $error .= 'El nombre del producto ya existe en la Base de Datos.<br>';
  37.                     }
  38.     }else{
  39. $query = sprintf("INSERT INTO productos(`codigodelproducto`,`tipodeproducto`,`serial`,`marca`,`modelo`,`color`,`anofabricacion`,`fabricante`,`diasdegarantia`,`proveedor`,`descripcionbreve`,`descripciondetallada`,`preciocompra`,`precioventa`,`descuento`,`diasdegarantiaotor`,`cantidad`,`comentarios`)
  40.            VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
  41.             mysql_real_escape_string($_POST['codigodelproducto']),
  42.             mysql_real_escape_string($_POST['tipodeproducto']),
  43.             mysql_real_escape_string($_POST['serial']),
  44.             mysql_real_escape_string($_POST['marca']),
  45.             mysql_real_escape_string($_POST['modelo']),
  46.             mysql_real_escape_string($_POST['color']),
  47.             mysql_real_escape_string($_POST['anofabricacion']),
  48.             mysql_real_escape_string($_POST['fabricante']),
  49.             mysql_real_escape_string($_POST['diasdegarantia']),
  50.             mysql_real_escape_string($_POST['proveedor']),
  51.             mysql_real_escape_string($_POST['descripcionbreve']),
  52.             mysql_real_escape_string($_POST['descripciondetallada']),
  53.             mysql_real_escape_string($_POST['preciocompra']),
  54.             mysql_real_escape_string($_POST['precioventa']),
  55.             mysql_real_escape_string($_POST['descuento']),
  56.             mysql_real_escape_string($_POST['diasdegarantiaotor']),
  57.             mysql_real_escape_string($_POST['cantidad']),
  58.             mysql_real_escape_string($_POST['comentarios']));
  59.         $sql = mysql_query($query);
  60.         # Redireccion a la página de logueo despues del registro.
  61.        echo "<SCRIPT LANGUAGE='JavaScript'>
  62.    window.alert('¡REGISTRO ACEPTADO!')
  63.    window.location.href='registrarproducto.php';
  64.    </SCRIPT>";
  65.         exit;
  66.     }
  67. }
  68. if(isset($error)){
  69.     echo $error;
  70.     unset($error);
  71. }
  72. ?>


BIEN EL PROBLEMA ES QUE AUNQUE LE DIGA A LAS VARIABLES $ERROR QUE LA GENTE DEBE LLENAR "codigodelproducto", "tipodeproducto", "marca", "color","proveedor","preciodeventa","cantidad","co mentarios"....... SI LLENO TODOS ESOS CAMPOS OBLIGATORIOS Y NO LLENO LOS DEMAS CAMPOS Y LOS DEJO EN BLANCO SIGUE DANDO ERROR.... Y LA IDEA ES QUE SOLO ME REVISE LOS CAMPOS OBLIGATORIOS Y LOS DEMAS SI NO LOS QUIERO LLENAR LOS DEJE EN BLANCO...

QUE PUEDO HACERR..... QUE ERROR TENGO EN EL CODIGO QUE NO LO VEO...

Última edición por Triby; 22/05/2014 a las 04:03 Razón: Eliminar formato de texto