Foros del Web » Programando para Internet » PHP »

Cerrar sesión & Consulta

Estas en el tema de Cerrar sesión & Consulta en el foro de PHP en Foros del Web. Buenas amigos, tengo 2 inquietudes la primera es que necesito tener un registro en mi proyecto de cuando un usuario inicia sesion y cuando cierra ...
  #1 (permalink)  
Antiguo 29/06/2011, 22:28
 
Fecha de Ingreso: junio-2011
Ubicación: Ccs
Mensajes: 27
Antigüedad: 12 años, 10 meses
Puntos: 3
Cerrar sesión & Consulta

Buenas amigos, tengo 2 inquietudes la primera es que necesito tener un registro en mi proyecto de cuando un usuario inicia sesion y cuando cierra sesion, yo tengo listas las pantallas de login.php y logout.php pero muy pocas personas cierran sesion entonces quedara abierta hasta un cierto tiempo, intente unos metodos que vi aqui en el foro y otro de otra web para cerrar sesion cuando cierre el navegador y cambie hacia otra web,dejare los link para que los vean los que me quieran ayudar.
Este no hace nada.
http://www.forosdelweb.com/f18/cerrar-sesion-php-cerrar-navegador-437629/

Y este me dice q no tengo esta variable ($HTTP_SERVER_VARS["HTTP_HOST"]) pero quien es "HTTP_HOST"?
http://www.desarrolloweb.com/articulos/2022.php


El otro problemilla es que mi proyecto se trata sobre un sistema para agencias de viajes he llegado a la parte que necesito validar si existe o no un cupo disponible en el vuelo que el usuario ha señalado.
Yo hice mi query en la consola y me arrojo un resultado positivo es decir me conto cuantos vuelos hay identicos pero no se como rescatar ese valor aqui dejo el query que estoy haciendo.

Código PHP:
Ver original
  1. $consulta= mysql_query("select codavion, count(codavion)as cantidad  from $tabla where origen='$origen' &&  destino='$destino' && partida='$partida' && fechaida='$fechaida' && clase='$clase'  group by codavion order by codavion");

Esta es mi consulta, necesito contar cuantos boletos hay comprados segun el origen,destino,hora,fecha,clase y por supuesto la aerolinea en este caso la aerolinea toma el valor de $tabla. Ya que tengo una tabla para cada aerolinea.

Gracias de antemano.

PD: a otra cosita, tengo formulario tipo radio y cuando alguien no selecciona ninguna opcion e intenta avanzar a la siguiente pantalla me dice que no tengo ningun valor, como hago para evitar eso? me refiero a poner como una opcion oculta con el valor "NULL" y asi yo poder validar si selecciono algo o no.
  #2 (permalink)  
Antiguo 30/06/2011, 00:37
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Cerrar sesión & Consulta

Ahhh que color escogiste!!! ... ingamelapupila!!!!

- Todo (o casi todo) lo que antes estaba en $HTTP_SERVER_VARS ahora debes "buscarlo" en $_SERVER
- "Quien" (o que) es HTTP_HOST, puedes verlo en el manual de PHP para la variable reservada $_SERVER
- Al ejecutar una consulta, se genera un recurso para acceso a los resultados (siempre que no haya error) y, para leer los registros, debes usar alguna de las funciones especificas de acuerdo a tus necesidades, revisa el manual, te dejo enlace solo a una: mysql_fetch_assoc()

PD: Muestra el codigo que usas para obtener el radio seleccionado, aunque, puede funcionar algo como:

Código PHP:
Ver original
  1. if(empty($_POST['nombre_del_radio'])) {
  2.     // Aqui muestras el error o asignar algun valor por default
  3. }
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 30/06/2011, 23:58
 
Fecha de Ingreso: junio-2011
Ubicación: Ccs
Mensajes: 27
Antigüedad: 12 años, 10 meses
Puntos: 3
Respuesta: Cerrar sesión & Consulta

Cita:
Iniciado por Triby Ver Mensaje
Ahhh que color escogiste!!! ... ingamelapupila!!!!

- Todo (o casi todo) lo que antes estaba en $HTTP_SERVER_VARS ahora debes "buscarlo" en $_SERVER
- "Quien" (o que) es HTTP_HOST, puedes verlo en el manual de PHP para la variable reservada [URL="http://www.php.net/manual/es/reserved.variables.server.php"]$_SERVER[/URL]
- Al ejecutar una consulta, se genera un recurso para acceso a los resultados (siempre que no haya error) y, para leer los registros, debes usar alguna de las funciones especificas de acuerdo a tus necesidades, revisa el manual, te dejo enlace solo a una: [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc()[/URL]

PD: Muestra el codigo que usas para obtener el radio seleccionado, aunque, puede funcionar algo como:

Código PHP:
Ver original
  1. if(empty($_POST['nombre_del_radio'])) {
  2.     // Aqui muestras el error o asignar algun valor por default
  3. }
Jejeje sorry por el color :D, estoy leyendo la informacion que me dijistes, gracias por la respuesta. La reviso y comento.
  #4 (permalink)  
Antiguo 02/07/2011, 12:18
 
Fecha de Ingreso: junio-2011
Ubicación: Ccs
Mensajes: 27
Antigüedad: 12 años, 10 meses
Puntos: 3
Respuesta: Cerrar sesión & Consulta

Aqui Dejo el Codigo
Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Agencia de Viajes</title>
  6. <link rel="stylesheet" type="text/css" href="vuelos.css"/>
  7.  
  8. </head>
  9. <body>
  10. <?php
  11. if(!isset($_SESSION["login"])){
  12.    
  13.  
  14. ?>
  15.  
  16. <fieldset id="form">
  17. <legend align="center">ALERTA</legend>
  18. <p align="center" >No ha iniciado sesion <a href="../login.php">Identifiquese</a> en nuestro sistema.</p><br>
  19. <p align="center" >Sino esta registrado puede  <a href="../registro.php">Registrarse</a></p><br>
  20. </fieldset>
  21. <?php
  22. }
  23. else {
  24.   if($_POST['origen']==$_POST['destino']){
  25.       ?>
  26.       <form action="comprar1.php" method="post" >
  27. <fieldset id="identi">
  28. <legend align="center">ALERTA</legend><BR>
  29.   <div align="center">
  30.   <p align="center" >Por Favor Seleccione dos Ubicaciones Distintas  </p><br>
  31.   <input type="hidden" name="aerolinea" value="<?php echo $_POST['aerolinea']; ?>">
  32.  <input type="submit" value="Regresar" class="btn" onclick = "this.form.action = 'comprar1.php'" />
  33.   </div>
  34.  
  35.   <?php
  36.   } else {
  37. $origen=$_POST['origen'];
  38. $destino=$_POST['destino'];
  39. $aerolinea=$_POST['aerolinea'];
  40.  
  41.  
  42.  
  43. $conexion= mysql_connect ("localhost", "ignacio", "xtreme")
  44. or die ("No se puede conectar con el servidor");
  45.  
  46. mysql_select_db ("agencia")
  47. or die ("No se puede seleccionar la base de datos");
  48.    
  49.     $consulta=mysql_query("SELECT id,codavion,origen,destino,partida FROM vuelos where relacion='$aerolinea' && origen='$origen' && destino='$destino'");
  50.     $consulta2=mysql_query("SELECT id,codavion,origen,destino,partida FROM vuelos where relacion='$aerolinea' && origen='$destino' && destino='$origen'");
  51.     $prueba=mysql_query("SELECT id,codavion,origen,destino,partida FROM vuelos where relacion='$aerolinea' && origen='$destino' && destino='$origen'");
  52. ?>
  53.     <form action="comprar3.php" method="post" >
  54. <?php
  55. $prueba_row=mysql_fetch_row($prueba);
  56. if($prueba_row){  ?>
  57.  
  58.  
  59.  
  60.     <fieldset id="identi">
  61. <legend align="center   ">SELECCIONE EL HORARIO DE SU PREFERENCIA</legend><BR>
  62.   <div align="center">
  63.    <table width="93%" border="1">
  64.   <tr>
  65.     <th width="9%">Vuelo</th>
  66.     <th width="16%" >Origen</th>
  67.     <th width="15%" >Destino</th>
  68.     <th width="9%" >Hora</th>
  69.     <th width="20%" >Fecha</th>
  70.      <th width="15%" >Clase</th>
  71.     <th width="16%" >Selección</th>
  72.   </tr>
  73.  
  74.     <?php
  75.     // Voy imprimiendo el primer select compuesto por los paises
  76.    
  77.     while($registro=mysql_fetch_row($consulta))
  78.     { ?> <tr>
  79.     <th><?php echo"".$registro[1]."";?>  </th>
  80.     <th ><?php echo"".$registro[2]."";?> </th>
  81.     <th ><?php echo"".$registro[3]."";?></th>
  82.     <th ><?php echo"".$registro[4]."";?></th>
  83.     <th width="20%" ><SELECT class="nac" name="mesida"> <OPTION value="NULL" selected>Mes</OPTION>
  84.                           <OPTION value=1>Enero</OPTION> <OPTION
  85.                           value=2>Febrero</OPTION> <OPTION value=3>Marzo</OPTION>
  86.                           <OPTION value=4>Abril</OPTION> <OPTION
  87.                           value=5>Mayo</OPTION> <OPTION value=6>Junio</OPTION>
  88.                           <OPTION value=7>Julio</OPTION> <OPTION
  89.                           value=8>Agosto</OPTION> <OPTION value=9>Septiembre</OPTION>
  90.                           <OPTION value=10>Octubre</OPTION> <OPTION
  91.                           value=11>Noviembre</OPTION> <OPTION
  92.                         value=12>Diciembre</OPTION></SELECT> <SELECT name="diaida" class="nac">
  93.                           <OPTION value="NULL" selected>Día</OPTION>
  94.                           <OPTION>1</OPTION> <OPTION>2</OPTION>
  95.                           <OPTION>3</OPTION> <OPTION>4</OPTION>
  96.                           <OPTION>5</OPTION> <OPTION>6</OPTION>
  97.                           <OPTION>7</OPTION> <OPTION>8</OPTION>
  98.                           <OPTION>9</OPTION> <OPTION>10</OPTION>
  99.                           <OPTION>11</OPTION> <OPTION>12</OPTION>
  100.                           <OPTION>13</OPTION> <OPTION>14</OPTION>
  101.                           <OPTION>15</OPTION> <OPTION>16</OPTION>
  102.                           <OPTION>17</OPTION> <OPTION>18</OPTION>
  103.                           <OPTION>19</OPTION> <OPTION>20</OPTION>
  104.                           <OPTION>21</OPTION> <OPTION>22</OPTION>
  105.                           <OPTION>23</OPTION> <OPTION>24</OPTION>
  106.                           <OPTION>25</OPTION> <OPTION>26</OPTION>
  107.                           <OPTION>27</OPTION> <OPTION>28</OPTION>
  108.                           <OPTION>29</OPTION> <OPTION>30</OPTION>
  109.                           <OPTION>31</OPTION></SELECT> <SELECT name="anoida" class="nac">
  110.                           <OPTION value="NULL" selected>Año</OPTION>
  111.                          <OPTION
  112.                           value="2012">2012</OPTION> <OPTION
  113.                           value="2011">2011</OPTION> </SELECT></th>
  114.                            <th ><SELECT class="nac" name="clase"> <OPTION value="NULL" selected>Clase</OPTION>
  115.                           <OPTION value="VIP">V.I.P</OPTION> <OPTION
  116.                           value="PRI">Primera Clase</OPTION> <OPTION value="ECO">Economica</OPTION>
  117.                           </SELECT>  </th>
  118.     <th ><INPUT type="radio" name="partida" value="<?php echo"".$registro[4]."";?>"></th>
  119.   </tr>
  120.                  
  121.     <?php }?>
  122.      </table>
  123.      <BR>
  124.      <table width="93%" border="1">
  125.   <tr>
  126.     <th width="9%">Vuelo</th>
  127.     <th width="16%" >Origen</th>
  128.     <th width="15%" >Destino</th>
  129.     <th width="9%" >Hora</th>
  130.     <th width="20%" >Fecha</th>
  131.      <th width="15%" >Clase</th>
  132.     <th width="16%" >Selección</th>
  133.   </tr>
  134. <?php
  135.     while($registro=mysql_fetch_row($consulta2))
  136.     { ?>
  137.    
  138.    
  139.  
  140.         <tr>
  141.     <th><?php echo"".$registro[1]."";?>  </th>
  142.     <th ><?php echo"".$registro[2]."";?> </th>
  143.     <th ><?php echo"".$registro[3]."";?></th>
  144.     <th ><?php echo"".$registro[4]."";?></th>
  145.     <th width="20%" ><SELECT class="nac" name="messo"> <OPTION value="NULL" selected>Mes</OPTION>
  146.                           <OPTION value=1>Enero</OPTION> <OPTION
  147.                           value=2>Febrero</OPTION> <OPTION value=3>Marzo</OPTION>
  148.                           <OPTION value=4>Abril</OPTION> <OPTION
  149.                           value=5>Mayo</OPTION> <OPTION value=6>Junio</OPTION>
  150.                           <OPTION value=7>Julio</OPTION> <OPTION
  151.                           value=8>Agosto</OPTION> <OPTION value=9>Septiembre</OPTION>
  152.                           <OPTION value=10>Octubre</OPTION> <OPTION
  153.                           value=11>Noviembre</OPTION> <OPTION
  154.                         value=12>Diciembre</OPTION></SELECT> <SELECT name="diaso" class="nac">
  155.                           <OPTION value="NULL" selected>Día</OPTION>
  156.                           <OPTION>1</OPTION> <OPTION>2</OPTION>
  157.                           <OPTION>3</OPTION> <OPTION>4</OPTION>
  158.                           <OPTION>5</OPTION> <OPTION>6</OPTION>
  159.                           <OPTION>7</OPTION> <OPTION>8</OPTION>
  160.                           <OPTION>9</OPTION> <OPTION>10</OPTION>
  161.                           <OPTION>11</OPTION> <OPTION>12</OPTION>
  162.                           <OPTION>13</OPTION> <OPTION>14</OPTION>
  163.                           <OPTION>15</OPTION> <OPTION>16</OPTION>
  164.                           <OPTION>17</OPTION> <OPTION>18</OPTION>
  165.                           <OPTION>19</OPTION> <OPTION>20</OPTION>
  166.                           <OPTION>21</OPTION> <OPTION>22</OPTION>
  167.                           <OPTION>23</OPTION> <OPTION>24</OPTION>
  168.                           <OPTION>25</OPTION> <OPTION>26</OPTION>
  169.                           <OPTION>27</OPTION> <OPTION>28</OPTION>
  170.                           <OPTION>29</OPTION> <OPTION>30</OPTION>
  171.                           <OPTION>31</OPTION></SELECT> <SELECT name="anoso" class="nac">
  172.                           <OPTION value="NULL" selected>Año</OPTION>
  173.           <OPTION
  174.                           value="2012">2012</OPTION> <OPTION
  175.                           value="2011">2011</OPTION> </SELECT></th>
  176.     <th ><SELECT class="nac" name="claseso"> <OPTION value="NULL" selected>Clase</OPTION>
  177.                           <OPTION value="VIP">V.I.P</OPTION> <OPTION
  178.                           value="PRI">Primera Clase</OPTION> <OPTION value="ECO">Economica</OPTION>
  179.                           </SELECT>  </th>
  180.     <th ><INPUT type="radio" name="venida" value="<?php echo"".$registro[4]."";?>"> </th>
  181.   </tr>
  182.     <?php }
  183.     ?></table>
  184.     <BR> <BR>
  185.    
  186.  
  187. <input type="hidden" name="aerolinea" value="<?php echo $_POST['aerolinea']; ?>">
  188. <input type="hidden" name="origen" value="<?php echo $_POST['origen']; ?>">
  189. <input type="hidden" name="destino" value="<?php echo $_POST['destino']; ?>">    
  190. <input type="submit" value="Regresar" class="btn" onclick = "this.form.action = 'comprar1.php'" />
  191. <input type="submit" value="Siguiente" class="btn"  onclick = "this.form.action = 'comprar3.php'" />
  192.  
  193. <BR><BR>
  194.  
  195. </fieldset>
  196. <?php
  197. }
  198.    else {
  199. ?>
  200. <form action="comprar1.php" method="post" >
  201. <fieldset id="identi">
  202. <legend align="center">ALERTA</legend><BR>
  203.   <div align="center">
  204.   <p align="center" >No Tenemos Vuelos Disponibles  </p><br>
  205.   <input type="hidden" name="aerolinea" value="<?php echo $_POST['aerolinea']; ?>">
  206.  <input type="submit" value="Regresar" class="btn" onclick = "this.form.action = 'comprar1.php'" />
  207.   </div>
  208.   <?php } }}
  209.  
  210. ?>
  211.  
  212.  
  213.  
  214.  
  215. </body>
  216. </html>
He encontrado el problema por el cual la consulta no me funciona pondre una imagen de como se muestra el codigo



La cuestion es que tengo los select con el mismo nombre :(
  #5 (permalink)  
Antiguo 02/07/2011, 12:31
 
Fecha de Ingreso: junio-2011
Ubicación: Ccs
Mensajes: 27
Antigüedad: 12 años, 10 meses
Puntos: 3
Respuesta: Cerrar sesión & Consulta

Tuve que postear de nuevo xq excede los 10000 caracteres. Como tengo los select con el mismo nombre imprimi la consulta con la que estaba revisando cuantos boletos han comprado con esas caracteristicas y me tope con esto

"select codavion, count(codavion)as cantidad from laser where origen='Maiquetia (MQV)' && destino='Porlamar (MAR)' && partida='07:00:00' && fechaida='2011-6-6' && clase='VIP' group by codavion order by codavion"

Si ven en fechaida me almacena 2011-6-6 pero en mi base de datos se almaceno 2011-06-06
Esto lo resolvi modificando el valor en los select.

Pero ahora como soluciono el problemita de los select con el mismo nombre? el problema esta en la fecha y la clase, como se repite tantas veces como vuelos disponibles hayan tendran el mismo nombre. Alguna forma de aislar esto?
  #6 (permalink)  
Antiguo 04/07/2011, 17:03
 
Fecha de Ingreso: junio-2011
Ubicación: Ccs
Mensajes: 27
Antigüedad: 12 años, 10 meses
Puntos: 3
Respuesta: Cerrar sesión & Consulta

Luego de varios dias modificando y modificando he logrado pasar esta etapa.
Pero ahora necesito registrar en mi base de datos cuando un usuario se logea y cuando se deslogea. El deslogeo lo se registrar si el presiona Cerrar Sesión pero como lo registro cuando el cierra el navegador?

Etiquetas: cerrar, sesión
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 20:54.