Ver Mensaje Individual
  #5 (permalink)  
Antiguo 28/10/2012, 16:42
KenMasters
 
Fecha de Ingreso: abril-2005
Ubicación: Piura - Perú
Mensajes: 189
Antigüedad: 19 años, 11 meses
Puntos: 0
Respuesta: problema consulta simple

tengo lo siguiente que ya he corregido, la idea es que logee y vaya mostrando ciertas cosas para ciertos niveles; pero no realiza creo ninguna consulta adjunto el code

config1.php
Código PHP:
Ver original
  1. <?
  2. // Configura los datos de tu cuenta
  3. $dbhost="localhost";
  4. $dbusername="root";
  5. $dbuserpass="123456";
  6. $dbname="yino";
  7.  
  8. // Conexión a la base de datos
  9. mysql_connect ($dbhost, $dbusername, $dbuserpass);
  10. // Seleccion de la base de datos
  11. mysql_select_db($dbname) or die("Cannot select database");
  12. ?>

Luego el archivo index.php

Código PHP:
Ver original
  1. <?
  2. require_once('config1.php');
  3. //cargar variables
  4. if($_POST['submit']) {
  5.     $user = $_POST["username"];
  6.     $pass = $_POST["password"];
  7. }
  8. //carga SESSION
  9. if ($_SESSION['username']) {
  10.     $user = $_SESSION['username'];
  11.     $nivel = $_SESSION['nivel'];
  12. }
  13. //funcion de identificacion
  14. if($_POST['submit']) {
  15.     echo "se envia submit";
  16.     $check_user = mysql_query('SELECT * FROM usuarios WHERE username= "  $user " and password= "  $pass " ');
  17.     $username_exist = mysql_num_rows($check_user);
  18.     echo $username_exist;
  19.     if ($username_exist > 0) { // identificacion de usuarios existosa
  20.         echo "$username_exist > o    TRUE";
  21.         $sql_nivel = 'SELECT * FROM usuarios WHERE username="  $user  "';
  22.         $checknivel = mysql_query($sql_nivel); 
  23.         //$num = mysql_numrows ($checknivel);
  24.         //$row = mysql_fetch_row($checknivel);
  25.         if($row = mysql_fetch_array($checknivel)) {    
  26.         //$row = mysql_fetch_assoc($checknivel);
  27.         //while $row = mysql_fetch_assoc($checknivel) {
  28.         $nivel  = $row['nivel'];
  29.        
  30.         session_register("username");
  31.         session_register("nivel");
  32.        
  33.         $_SESSION['username'] = $user;
  34.         $_SESSION['nivel'] = $nivel;
  35.         }
  36.         echo "<font color=\"#FF0000\"><b>Thank you for login in, you will be redirected to the protected pages in 2 seconds <META HTTP-EQUIV=\"refresh\" CONTENT=\"2; URL=index.php\"></b></font>";
  37.     }
  38. }
  39. if ($_GET['func'] == "logout") {
  40.     session_start();
  41.     // vaciarla
  42.     $_SESSION = array();
  43.     session_destroy();
  44. } elseif ($_GET['func'] == "err1") {
  45.     echo "error de logeo";
  46. } else {
  47.     echo "";
  48. }
  49. ?>
  50. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  51. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  52. <head>
  53.   <title><? echo $website; ?></title>
  54.   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  55.   <meta name="generator" content="handmade" />
  56.     <style type="text/css">
  57.     <!--
  58.         body {
  59.             font-family: Arial, Helvetica, sans-serif;
  60.             font-size: 14px;
  61.             background-color: #DDDDDD;
  62.         }
  63.         .cnt {
  64.             text-align: center;
  65.         }
  66.         .cnt_welcome {
  67.             font-size: 16px;
  68.             font-weight: bold;
  69.             text-align: center;
  70.         }
  71.         .cnt_powered {
  72.             font-size: 14px;
  73.             font-weight: bold;
  74.             text-align: center;
  75.         }
  76.         .cnt_small {
  77.             font-size: 12px;
  78.             text-align: center;
  79.             padding-top: 50px;
  80.         }
  81.         .head_line {
  82.             background-color: #BBBBBB;
  83.         }
  84.         .main_table {
  85.             border: solid 1px #9D9992;
  86.             font-size: 13px;
  87.         }
  88.         h4 {
  89.             font-size: 12px;
  90.             color: #DD0000;
  91.             text-align: center;
  92.         }
  93.         .button {
  94.             border: 1px solid #55555;
  95.             font-weight: bold;
  96.         }
  97.     -->
  98. </style>
  99.  
  100. </head>
  101. <body>
  102.  
  103. <table width="790" border="0" cellspacing="0" cellpadding="0">
  104.   <tr>
  105.     <td colspan="2"><img src="images/logo_elearning.jpg" alt="" width="300" height="82" /></td>
  106.   </tr>
  107.   <tr>
  108.     <td width="250">
  109.     Bienvenido <? echo $user;  ?> <br />
  110.     Nivel : <? echo $nivel; ?>  <br />
  111.     <blockquote>
  112.     - Inicio<br />
  113.     - Mis cursos<br />
  114.     - Inscripcion<br />
  115.     - <a href="?func=logout">Salir</a><br />
  116.     </blockquote>
  117.     <br />
  118.     </td>
  119.     <td width="540">
  120.     <?
  121.     //if (!$_SESSION['username']) {
  122.     if ($_GET['func'] == "login") {
  123.     ?>
  124.         <center>
  125.         <h2>Bienvenido al sistema de educacion e-learning para el aprendizaje de corriente alterna</h2>
  126.         <form name="form1" method="post" action="index.php">
  127.         Username:<br><input name="username" type="text" id="username"><br>
  128.         Password:<br><input name="password" type="password" id="password"><br><br>
  129.         <input name="submit" type="submit" id="submit" value="Login!"><br><br>
  130.         </form>
  131.         </center>
  132.     <?
  133.     } else {
  134.         echo "se muestra el bloque de cursso que lleva el alumno o profesor, segun varios aspectos";
  135.     }
  136.     //Se carga el contexto para el cpanel segun las funciones enviadas por metodo $_GET
  137.     if ($_GET['func'] == "logout") {
  138.             echo "Desconectando del sistema ...";  
  139.             echo "<font color=\"#FF0000\"><b>Logout satisfactorio<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; URL=index.php?func=login\"></b></font>";
  140.     } elseif ($_GET['func'] == "x") {
  141.             echo "x";
  142.     }
  143.     ?>
  144.     </td>
  145.   </tr>
  146.   <tr>
  147.     <td colspan="2"><center><font face="courier" size="1.5">Desing by ....</font></center></td>
  148.   </tr>
  149. </table>
  150. </body>
  151. </html>