PHP - <select name="cmbotipgasto">

 
Vista:
sin imagen de perfil
Val: 557
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

<select name="cmbotipgasto">

Publicado por zendi (1056 intervenciones) el 28/03/2014 03:33:13
tengo un codigo con un <select name="cmbotipgasto"> desde ahi debo halar el codigo para grabar un registro en otra tabla pero no lo esta haciendo.


cuando selecciono el tipode gasto se ve que es de tipo caracter lo que necesito es que guarde el codigo de dicho tipo de gastos.

este es el codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
   $connect = pg_connect("host=localhost port=5432 dbname=administra user=postgres password=1234");
   $diarios = "SELECT * FROM diario ORDER BY descripcion";
   $tipo_gasto = "SELECT * FROM tipos_gastos ORDER BY descripcion";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gastos</title>
<style type="text/css">
  .sr {
    background-color: #FFFFCF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
      }
  input.color1 {background-color: #00CC99; font-weight: bold; font-size: 12px; color: white;}
</style>
</head>
<body>
 <?php
     $hoy=date('d-m-Y');
  ?>
 
<form action="AgregaGastos.php" method='POST'>
<fieldset style='width:auto'><LEGEND>Gastos</LEGEND>
   <table align='center'>
<tr>
     <td align='right' class='sr' >Gasto:</td>
     <td><select name="cmbogasto"><option value="0">[Seleccione un gasto]</option>
 
<?php
 
$diarios = @pg_query($connect,$diarios);
while($select2 = @pg_fetch_array($diarios)){
			$codigo = $select2['codigo'];
            $descrip = $select2['descripcion'];
            echo "<OPTION VALUE='$descrip'>$descrip</OPTION>";
          }
?>
        </select></td></tr>
 
<!--tipo gastos-->
<tr>
     <td align='right' class='sr' >Tipo Gasto:</td>
     <td><select name="cmbotipgasto"><option value="0">[Seleccione un Tipo de Gasto]</option>
<?php
$tipo_gasto = @pg_query($connect,$tipo_gasto);
while($select3 = @pg_fetch_array($tipo_gasto)){
			$codigo = $select3['codigo'];
            $descrtipogasto = $select3['descripcion'];
            echo "<OPTION VALUE=$descrtipogasto>$descrtipogasto</OPTION>";
          }
 
 
?>
 
        </select></td></tr>
 
	  <tr>
		<td class="sr" align='right' style="text-decoration:none">Monto:</td>
		<td class="sr"><input type="text" name="monto" size="5" maxlength="5" align="right"/></td>
	  </tr>
	  <tr>
		<td class="sr" align='right' style="text-decoration:none">Fecha:</td>
		<td class="sr"><input type="text" value="<?php echo $hoy;?>" readonly=".F." name="fecha" size="10" maxlength="10" align="right"/></td>
	  </tr>
	</table>
<table align="center">
   <tr>
    <td>
         <input class="color1" type="submit" name="action" value="Guardar"/>
         <input class="color1" type="reset" value="Deshacer">
         <INPUT class="color1" TYPE="BUTTON" VALUE="Salir" ONCLICK="window.location.href='menu1.php'">
    </td>
    </tr>
</table>
</fieldset>
<br/>
<?php
 
$descrip = $_POST['cmbogasto'];
$monto   = $_POST['monto'];
$fecha   = $_POST['fecha'];
$tipogasto = $_POST['cmbotipgasto'];
$anio  = substr($fecha,6,4);
$mes   = substr($fecha,3,2);
$día   = substr($fecha,0,2);
$fechagasto = $anio."-".$mes."-".$día;
///colocar el tipo de gastos
$guardar = "INSERT INTO gastos1(
						cod_tipo_gasto,
						descripcion,
						monto,
						fecha) 
				 VALUES ($tipogasto,
				        '$descrip',
						 $monto,
						 '$fechagasto')";
 
$todosgastos = "SELECT * FROM gastos1 ORDER BY fecha";
$seleccionados = @pg_query($connect,$todosgastos);
 
echo "<table align='center' border='1' bordercolor='#00CC99' bgcolor='#99CC00'>
       <tr>
           <th width='100' style='font-size:15px;'>Gasto
           <th width='100' style='font-size:15px;'>Monto
           <th width='100' style='font-size:15px;'>Fecha
           <th width='100' style='font-size:15px;'>Codigo
           <th width='100' style='font-size:15px;'>&nbsp;
		   
  	   </tr>
	 </table>";
        echo "<table border='1' bordercolor='#FFCC99'>";
		$total=0;
 
while($select4 = @pg_fetch_array($seleccionados)):
	 $descripcion = $select4['descripcion'];
	 $monto       = $select4['monto'];
	 $fecha       = $select4['fecha'];
     $anio  = substr($fecha,0,4);
     $mes   = substr($fecha,5,2);
     $día   = substr($fecha,8,2);
	 $articulo    = $select4['codigo'];
 
                echo "<table align='center' border='1' bordercolor='#FFCC99' bgcolor='#99CC00'>
	            <tr class='sr'>
			       <td width='100' align='left' style='font-size:10px;'>$descripcion</td>
			       <td width='100' align='center' style='font-size:10px;'>$monto</td>
			       <td width='100' align='center' style='font-size:10px;'>$día"."/"."$mes"."/"."$anio</td>
			       <td width='100' align='center'><a href='modificar.php?art=$articulo' title='Modificar el gasto'>$articulo</td>

 		           <td width='100' style='font-size:10px;'>
				   <a href='eliminagasto.php?cod=$articulo'
				   onClick='return confirm(\"¿Está Seguro de Eliminar este Registro?\");'
				   <img src='img/equis.gif' title='Eliminar' heigth='25' width='25'>Eliminar</a></td>

						</tr>
        		      </table>";
     	  $total +=$monto;
		  $ntotal = number_format($total,2,',','.');
					  
            endwhile;
///
//$fechaActual=time();
//$fechaARevisar=strtotime($fecha); 
//echo $fechaARevisar;
////# $Fecha es tu variable que contiene la fecha. Tiene que estar en formato yyyy-mm-dd #Obtenemos la diferencia en segundos
// $diff=$fechaActual-$fechaARevisar;
//  #2592000 de segundos equivale a 30 días 
//  #5184000 de segundos equivale a 60 días 
//if($diff<2592000) { 
//  echo "Han pasado menos de 30 días";
//} elseif($diff<5184000){
//   echo " Han pasado menos de 60 días";
//}else{ 
//   echo " Han pasado mas de 60 días";
//}
///////
$dtotal = "SELECT COUNT(*) AS tot FROM gastos1";
$totgas = @pg_query($connect,$dtotal);
while($select1 = @pg_fetch_array($totgas)):
     $gasto    = $select1['tot'];
     echo"<table align='center' border='1' bordercolor='#FFCC99'>
	      <tr class='sr'>
            <td width='150' style='color:#000000'>Cantidad de Gastos
			<td width='150' align='right'>$gasto
		  </tr></table>";
endwhile;
echo "<br><table align='center' border='1' bordercolor='#FFCC99' bgcolor='#99CC00'>
	        <tr class='sr'>
	          <td width='150' style='color:#000000'>Total
			  <td width='150' align='right'>$ntotal
  		    </tr></table>";
 
 
?>
</form>
</body>
</html>



anexo las tablas tambien.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

<select name="cmbotipgasto">

Publicado por xve (6935 intervenciones) el 28/03/2014 11:29:18
Hola Zendi, el problema lo tienes en el desplegable, que pones la descripción en el value...

En vez de:
1
echo "<OPTION VALUE=$descrtipogasto>$descrtipogasto</OPTION>";
prueba esto:
1
echo "<OPTION VALUE='".$codigo."'>$descrtipogasto</OPTION>";
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 557
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

<select name="cmbotipgasto">

Publicado por zendi (1056 intervenciones) el 28/03/2014 17:52:18
Que tal Xve.Efectivamente, antes de entrar al foro ya lo habia resuelto, de todos modos
aqui muestro la solucion. Ahora funciona.
1
2
3
4
5
6
7
8
9
10
<?php
$tipo_gasto = "SELECT * FROM tipos_gastos ORDER BY descripcion";
$tipo_gasto = @pg_query($connect,$tipo_gasto);
while($select3 = @pg_fetch_array($tipo_gasto))
		  {
			$cCodigo = $select3['codigo'];
            $descrip = $select3['descripcion'];
            echo "<OPTION VALUE='$cCodigo'>$descrip</OPTION>";
          }
?>
por supuesto no habia percatado que era asi.
Gracias por comentar y ayudar.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar