Ver Mensaje Individual
  #2 (permalink)  
Antiguo 06/06/2006, 14:24
Avatar de seik!
seik!
 
Fecha de Ingreso: mayo-2006
Mensajes: 492
Antigüedad: 17 años, 10 meses
Puntos: 6
asi lo tengo yo espero sirva...

Código PHP:
// este es el formulario.....

<?php
                
require("../config.inc.php");
?>

<?php                                 
                        
                $strsql 
"SELECT num_oficio FROM oficio";
                
$result select_data($strsql, &$fil, &$col);
                
$row=mysql_fetch_array($result);
                
$consulta $row["num_oficio"];
?>
<html>
<head>

<title>Agregar Oficio</title>
    <link href="../config.inc.css" rel="stylesheet" type="text/css">
</head>

<body topmargin="0" leftmargin="0">

<form method="POST" enctype="multipart/form-data" name="form" action="oficio_ag.php" ALIGN="top">
        
            <table width="510" border="0" cellpadding="0" cellspacing="2">
                <tr><td height="40" colspan="3" class="ti_14_blanco" style="font-size:20;" align="center" bgcolor="#333399">DETALLE NUEVO DOCUMENTO</td></tr>
                
                <tr><td height="20"></td>
                <tr>
                    <td height="25" width="150" class="ti_12_negro" bgcolor="#ccffff">&nbsp;Nº de documento</td>
                    <td width="10" class="ti_12_negro" align="center">:</td>
                    <td width="320" class="ti_12_negro"><input type="text" name="num_oficio" style="width:120;" class="text110"  maxlength="15"  size="10" onblur="Valida(this);"></td>
                </tr>
                <tr><td height="7"></td></tr>
                <tr>
                    <td height="25" width="150" class="ti_12_negro" bgcolor="#ccffff">&nbsp;Nombre de documento</td>
                    <td width="10" class="ti_12_negro" align="center">:</td>
                    <td width="320" class="ti_12_negro"><input type="text" name="nom_oficio" style="width:320;" size="20" class="text110"  maxlength="20" onChange="javascript:this.value=this.value.toLowerCase();"></td>
                </tr>
                <tr><td height="7"></td></tr>
                <tr>
                    <td height="25" width="180" class="ti_12_negro" valign="top" bgcolor="#ccffff">&nbsp;Descrip. documento ANT.</td>
                    <td width="10" class="ti_12_negro" align="center" valign="top">:</td>
                    <td width="320" class="ti_12_negro"><textarea name="ant_oficio" class="text110" style="width:320;" rows="3" onChange="javascript:this.value=this.value.toLowerCase();"></textarea></td>
                </tr>
                <tr><td height="7"></td></tr>
                <tr>
                    <td height="25" width="180" class="ti_12_negro" valign="top" bgcolor="#ccffff">&nbsp;Descrip. documento MAT.</td>
                    <td width="10" class="ti_12_negro" align="center" valign="top">:</td>
                    <td width="320" class="ti_12_negro"><textarea name="mat_oficio" class="text110" style="width:320;" rows="3" onChange="javascript:this.value=this.value.toLowerCase();"></textarea></td>
                </tr>
                <tr><td height="7"></td></tr>
                <tr>
                    <td height="25" width="150" class="ti_12_negro" bgcolor="#ccffff">&nbsp;Fecha del documento</td>
                    <td width="10" class="ti_12_negro" align="center">:</td>
                    <td width="320" class="ti_12_negro"><input type="text" name="fecha_oficio" class="text110" maxlength="10" onblur="valFecha(this)"><font size="0" color="#C0C0C0">&nbsp;Ej: 31/12/2006</font></td>
                </tr>
                <tr><td height="7"></td></tr>
                <tr>
                    <td height="25" width="150" class="ti_12_negro" bgcolor="#ccffff">&nbsp;Fecha de Recepción</td>
                    <td width="10" class="ti_12_negro" align="center">:</td>
                    <td width="320" class="ti_12_negro"><input type="text" name="fecha_recepcion_oficio" class="text110" maxlength="10" onblur="valFecha(this)"><font size="0" color="#C0C0C0">&nbsp;Ej: 31/12/2006</font></td>
                </tr>
                <tr><td height="7"></td></tr>
                <tr>
                    <td height="25" width="150" class="ti_12_negro" bgcolor="#ccffff">&nbsp;Estado documento</td>
                    <td width="10" class="ti_12_negro" align="center">:</td>
                    <td width="320" class="ti_12_negro">
                        <select name="selestado_oficio" disabled>
                               <option value="Ingresado" selected>Ingresado</option> 
                           </select>
                    </td>
                </tr>                
                <tr><td height="7"></td></tr>                
                <tr>
                    <td height="25" width="150" class="ti_12_negro" bgcolor="#CCFFFF">&nbsp;Organismo Regulador</td>
                    <td width="10" class="ti_12_negro" align="center">:</td>
                    <td width="320" class="ti_12_negro">
                        <select name="selorganismo" >
                               <option value="sec">SEC</option> 
                               <option value="cne">CNE</option> 
                               <option value="cdec">CDEC</option> 
                        </select>
                        <input type="hidden" name="hidorganismo" value="<?php print($row["organismo"]);?>">
                        <script language="vbscript">
                            document.forms.form.selorganismo.value=document.forms.form.hidorganismo.value
                        </script>
                    </td>
                </tr>                
                <tr><td height="7"></td></tr>                
                <tr>
                    <td height="25" width="150" class="ti_12_negro" bgcolor="#CCFFFF">&nbsp;Tipo Documento</td>
                    <td width="10" class="ti_12_negro" align="center">:</td>
                    <td width="320" class="ti_12_negro">
                        <select name="seltipo_oficio">
                               <option value="Oficio Circular">Oficio Circular</option>
                            <option value="Resolución Exenta">Resolución Exenta</option>   
                               <option value="Cartas">Cartas</option>
                            <option value="Respuesta de Facturación">Respuesta de Facturación</option>
                        </select>
                        <input type="hidden" name="hidtipo_oficio" value="<?php print($row["tipo_oficio"]);?>">
                        <script language="vbscript">
                            document.forms.form.seltipo_oficio.value=document.forms.form.hidtipo_oficio.value
                        </script>
                    </td>
                </tr>
                <tr><td height="7"></td></tr>                        
                <tr>
                    <td height="25" width="150" class="ti_12_negro" bgcolor="#ccffff">Adjuntar documento&nbsp;</td>
                    <td width="10" class="ti_12_negro" align="center">:</td>
                    <td width="320" class="ti_12_negro"><input type="file"  name="archivo" size="20" ></td>
                </tr>                
                <tr><td height="20"></td></tr>
                <tr>
                    <td height="25" width="150" class="ti_12_negro"></td>
                    <td width="10" class="ti_12_negro" align="center"></td>                
                    <td width="320" class="ti_12_negro"><input type="button" value="Enviar" class="button" onClick="validar(this.form)">&nbsp&nbsp<input type="button" class="button" name="cmdCancelar" value="Cancelar" onclick="javascript:window.close();">&nbsp&nbsp<input type="reset" value="Borrar" class="button" name="erase" ></td>
            
                </tr>
                <tr><td height="20"></td></tr>
             </form>    

            </table>
</center>
</body>
</html>

y este es la pagina onde rescato comparo y guardo si no existe ... si existe vuelvo con la funcion
<input type='button' class='button' name='cmdsalir' value='Regresar' onclick='javascript:history.back()'>
asi kedara...

Código PHP:
<?php
         
require("../config.inc.php");

?>
<link href="../config.inc.css" rel="stylesheet" type="text/css">


<?php 
        
// Paso 1: Recibimos el formulario: 
        
$num_oficio=$_POST["num_oficio"];

        
// Obviamente conectamos 
        
mysql_connect("localhost""root"""); 
        
mysql_select_db("sec"); 

        
// Paso 2: Hacemos la consulta a la Tabla por el documento
        
$busquedamysql_query("SELECT num_oficio FROM oficio WHERE num_oficio='".$num_oficio."'"); 


        
// Paso 3: vemos si hubo coincidencias 
        
if(mysql_num_rows($busqueda)>0) { // ó " !=0 " como se quiera ver 
       // Inciso a:  
                  
echo "<center>
                <table> 
                        <tr>
                            <td height='100' width='30' class='ti_12_negro' ></td>
                        </tr>
                        <tr>
                            <td height='40' width='330' align='center' class='ti_14_azul' bgcolor='#CCFFFF'>Número de documneto ya existe dentro de los registros, favor ingrese nuevamente</td>
                        </tr>
                        <tr>
                            <td height='30'></td>
                        </tr>
                        <tr>
                            <td height='40' width='330' align='center'><input type='button' class='button' name='cmdsalir' value='Regresar' onclick='javascript:history.back()'></td>
                        </tr>
                </table>"
;           
                } else {
?>
   

Datos ingresados correctamente                     <input type="button"  name="cmdaceptar" value="Aceptar" class="button" onclick="javascript:window.close();">

<?php
                $nom_oficio
=$_POST["nom_oficio"];
                
$ant_oficio=$_POST["ant_oficio"];
                
$mat_oficio=$_POST["mat_oficio"];
                
$fecha_oficio=$_POST["fecha_oficio"];
                
$fecha_recepcion_oficio=$_POST["fecha_recepcion_oficio"];
                
$estado_oficio =$_POST["selestado_oficio"];
                
$tipo_oficio=$_POST["seltipo_oficio"];
                
$organismo=$_POST["selorganismo"];
                    
                
$link mysql_connect("localhost""root""") or die("Could not connect to database!");
                
mysql_select_db("sec") or die("Could not select database!");
                
                
$query "INSERT INTO oficio (nom_oficio, num_oficio, ant_oficio";
                
$query.= ", mat_oficio, fecha_oficio, fecha_recepcion_oficio, archivo, estado_oficio, tipo_oficio, organismo) VALUES ";
                
$query.= "('".$nom_oficio."',".$num_oficio.",'".$ant_oficio."','".$mat_oficio."'";
                
$query.= ", '".$fecha_oficio."','".$fecha_recepcion_oficio."','".$nombre_archivo."','".$estado_oficio."','".$tipo_oficio."','".$organismo."')";
                
$result mysql_query($query$link);
?>
    
<?php
        $num_oficio_evento
=$num_oficio;
        
$evento_tipo "Ingreso datos";    
        
$evento_fecha $gfecha_hora_sistema;
    
        
$query "INSERT INTO evento (num_oficio_evento, evento_tipo, evento_fecha) VALUES";
        
$query.= "(".$num_oficio_evento.",'".$evento_tipo."','".$evento_fecha."')";
            
        
$result2 mysql_query($query$link);
    
?>

<?php }?>