Foros del Web » Programando para Internet » PHP »

problema consulta simple

Estas en el tema de problema consulta simple en el foro de PHP en Foros del Web. tengo el siguiente código; de autentificacionde usuarios, y con nivel de jerarquiza.. pero me sale error de Código PHP: Parse error :  syntax error ,  unexpected T_VARIABLE ,  ...
  #1 (permalink)  
Antiguo 28/10/2012, 01:54
 
Fecha de Ingreso: abril-2005
Ubicación: Piura - Perú
Mensajes: 189
Antigüedad: 19 años
Puntos: 0
problema consulta simple

tengo el siguiente código; de autentificacionde usuarios, y con nivel de jerarquiza.. pero me sale error de

Código PHP:
Parse errorsyntax errorunexpected T_VARIABLEexpecting '(' in E:allenwwwoctubre2012trabajo_yino1index.php on line 92 
lo unico que quiero es que logee y muestre que nivel es; y las paginas seguras segun el nivel, porque hay dos niveles profesores y alumnos,

el codigo del error lo adjunto

Código PHP:
<?
session_start
();
require_once(
'config1.php');
//cargar variables
$user $_POST["username"];
$pass $_POST["password"];



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
  <title><? $website ?></title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta name="generator" content="handmade" />
    <style type="text/css">
    <!--
        body {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 14px;
            background-color: #DDDDDD;
        }
        .cnt {
            text-align: center;
        }
        .cnt_welcome {
            font-size: 16px;
            font-weight: bold;
            text-align: center;
        }
        .cnt_powered {
            font-size: 14px;
            font-weight: bold;
            text-align: center;
        }
        .cnt_small {
            font-size: 12px;
            text-align: center;
            padding-top: 50px;
        }
        .head_line {
            background-color: #BBBBBB;
        }
        .main_table {
            border: solid 1px #9D9992;
            font-size: 13px;
        }
        h4 {
            font-size: 12px;
            color: #DD0000;
            text-align: center;
        }
        .button {
            border: 1px solid #55555;
            font-weight: bold;
        }

</style>

</head>
<body>

<table width="790" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2"><img src="images/logo_elearning.jpg" alt="" width="300" height="82" /></td>
  </tr>
  <tr>
    <td width="250">
    Bienvenido <? echo $_SESSION['username'];  ?> <br />
    Nivel : <? echo $_SESSION['nivel']; ?>
    <br />
    <blockquote>
    - Inicio<br />
    - Mis cursos<br />
    - Inscripcion<br />
    - Salir <br />
    </blockquote><br />
    </blockquote>
    </td>
    <td width="540">
    <? if($_POST['submit']){
    
$checkuser mysql_query('SELECT * FROM usuarios WHERE username= "  $user " and password= "  $pass " ');
    
$username_exist mysql_num_rows($checkuser);
    
    if (
$username_exist>0// identificacion de usuarios existosa
        
$checknivel mysql_query('SELECT * FROM usuarios WHERE username="  $user  "');    
        
//$num = mysql_numrows ($checknivel); 
        //$row = mysql_fetch_row($checknivel)  
        //$row = mysql_fetch_assoc($checknivel);
        
while $row mysql_fetch_assoc($checknivel) {
        echo 
$row["1"];
        ]
        
session_register("username");
        
session_register("nivel");
        
        
$_SESSION['username'] = $user;
        
$_SESSION['nivel'] = $row['nivel'];
        
//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>";
    
} else {
    
?>

        <center>
        <h2>Bienvenido al sistema de educacion e-learning para el aprendizaje de corriente alterna</h2>
        <form name="form1" method="post" action="index.php">
        Username:<br>
        <input name="username" type="text" id="username">
        <br>
        Password: <br>
        <input name="password" type="password" id="password">
        <br>
        <br>
        <input name="submit" type="submit" id="submit" value="Login!">
        <br>
        <br>
        </form>
        </center>
    
    <? ?>
    </td>
  </tr>
  <tr>
    <td colspan="2"><center><font face="courier" size=1.5">Desing by KenMasters</font></center></td>
  </tr>
</table>

Mi version de Php es 5.2
  #2 (permalink)  
Antiguo 28/10/2012, 06:32
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 5 meses
Puntos: 2658
Respuesta: problema consulta simple

Problema de PHP, No de MySQL.
Paso el post al foro correcto.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #3 (permalink)  
Antiguo 28/10/2012, 14:37
Avatar de rodrigo791  
Fecha de Ingreso: noviembre-2009
Ubicación: Uruguay
Mensajes: 1.339
Antigüedad: 14 años, 5 meses
Puntos: 168
Respuesta: problema consulta simple

tenes muchos problemas de cierres de peréntesis, cosas al aire que no se saben ni que hacen.

hay un while al cual le falta un paréntesis con el cual comienza la condición del mismo, tenes un paréntesiso recto ] que no se que hace ahí, un else que tampoco se que hace ahí
No tenes cerraro body, html, etc.
  #4 (permalink)  
Antiguo 28/10/2012, 14:49
Avatar de ERICK59  
Fecha de Ingreso: octubre-2012
Ubicación: Santo Domingo
Mensajes: 6
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: problema consulta simple

Como mensionaron antes tienes mucho errores de sierre aqui corregi el codigo prueba ahora
Código PHP:
Ver original
  1. <?
  2. require_once('config1.php');
  3. //cargar variables
  4. $user = $_POST["username"];
  5. $pass = $_POST["password"];
  6.  
  7.  
  8.  
  9. ?>
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  11. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  12. <head>
  13.   <title><? $website ?></title>
  14.   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  15.   <meta name="generator" content="handmade" />
  16.     <style type="text/css">
  17.     <!--
  18.         body {
  19.             font-family: Arial, Helvetica, sans-serif;
  20.             font-size: 14px;
  21.             background-color: #DDDDDD;
  22.         }
  23.         .cnt {
  24.             text-align: center;
  25.         }
  26.         .cnt_welcome {
  27.             font-size: 16px;
  28.             font-weight: bold;
  29.             text-align: center;
  30.         }
  31.         .cnt_powered {
  32.             font-size: 14px;
  33.             font-weight: bold;
  34.             text-align: center;
  35.         }
  36.         .cnt_small {
  37.             font-size: 12px;
  38.             text-align: center;
  39.             padding-top: 50px;
  40.         }
  41.         .head_line {
  42.             background-color: #BBBBBB;
  43.         }
  44.         .main_table {
  45.             border: solid 1px #9D9992;
  46.             font-size: 13px;
  47.         }
  48.         h4 {
  49.             font-size: 12px;
  50.             color: #DD0000;
  51.             text-align: center;
  52.         }
  53.         .button {
  54.             border: 1px solid #55555;
  55.             font-weight: bold;
  56.         }
  57.  
  58. </style>
  59.  
  60. </head>
  61. <body>
  62.  
  63. <table width="790" border="0" cellspacing="0" cellpadding="0">
  64.   <tr>
  65.     <td colspan="2"><img src="images/logo_elearning.jpg" alt="" width="300" height="82" /></td>
  66.   </tr>
  67.   <tr>
  68.     <td width="250">
  69.     Bienvenido <? echo $_SESSION['username'];  ?> <br />
  70.     Nivel : <? echo $_SESSION['nivel']; ?>
  71.     <br />
  72.     <blockquote>
  73.     - Inicio<br />
  74.     - Mis cursos<br />
  75.     - Inscripcion<br />
  76.     - Salir <br />
  77.     </blockquote><br />
  78.     </blockquote>
  79.     </td>
  80.     <td width="540">
  81.     <? if($_POST['submit']){
  82.     $checkuser = mysql_query('SELECT * FROM usuarios WHERE username= "  $user " and password= "  $pass " ');
  83.    
  84.     $username_exist = mysql_num_rows($checkuser);
  85.    
  86.    
  87.     if ($username_exist>0){ // identificacion de usuarios existosa
  88.         $checknivel = mysql_query('SELECT * FROM usuarios WHERE username="  $user  "');    }
  89.         //$num = mysql_numrows ($checknivel);
  90.         //$row = mysql_fetch_row($checknivel)  
  91.         //$row = mysql_fetch_assoc($checknivel);
  92.         while ($row = mysql_fetch_assoc($checknivel)){
  93.         echo $row["1"];
  94.         }
  95.         session_register("username");
  96.         session_register("nivel");
  97.        
  98.         $_SESSION['username'] = $user;
  99.         $_SESSION['nivel'] = $row['nivel'];
  100.         //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>";
  101.     } else {
  102.     ?>
  103.  
  104.         <center>
  105.         <h2>Bienvenido al sistema de educacion e-learning para el aprendizaje de corriente alterna</h2>
  106.         <form name="form1" method="post" action="index.php">
  107.         Username:<br>
  108.         <input name="username" type="text" id="username">
  109.         <br>
  110.         Password: <br>
  111.         <input name="password" type="password" id="password">
  112.         <br>
  113.         <br>
  114.         <input name="submit" type="submit" id="submit" value="Login!">
  115.         <br>
  116.         <br>
  117.         </form>
  118.         </center>
  119.    
  120.     <?php } ?>
  121.     </td>
  122.   </tr>
  123.   <tr>
  124.     <td colspan="2"><center><font face="courier" size=1.5">Desing by KenMasters</font></center></td>
  125.   </tr>
  126. </table>
  127. </body>
  128. </html>

Última edición por ERICK59; 28/10/2012 a las 15:18
  #5 (permalink)  
Antiguo 28/10/2012, 16:42
 
Fecha de Ingreso: abril-2005
Ubicación: Piura - Perú
Mensajes: 189
Antigüedad: 19 años
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>

Etiquetas: simple
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 12:37.