Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/10/2010, 01:28
vBArgentina
 
Fecha de Ingreso: octubre-2010
Ubicación: Mountain View, United States.
Mensajes: 87
Antigüedad: 14 años, 3 meses
Puntos: 1
Exclamación MySQL no reconoce ELSE.

Hola chicos, estoy teniendo un problemita con una consulta MySQL en PHP.

Mi codigo es este :


Código PHP:
<html>
<head>
<title>CONSULTA</title>
<head>
</head>
<body>
<form action="on.php" method="post">
<BR><BR><BR>
<center>
<table border=5>
<tr>
<td>Ver ONLINE</td>
<td><input name="caja1" size="18" value= ""></td>
</tr>
<TR>
<TD><input type=SUBMIT name=BOTON2 value ="Consultar"></TD>
<TD><input type=RESET name=BOTON1 value ="Borrar"></TD>
</TR>
</table>
</center>
</form>
</body>
</html>


<?php
$link 
mysql_connect("localhost""root""******");
mysql_select_db("forum",$link);
$sql "select * from session where userid ='".mysql_escape_string($_POST['caja1'])."'";
$sql mysql_query($sql) or die(mysql_error());  
while(
$row mysql_fetch_array($sql))
{
echo 
"<b>Conectado</b><img src=images/user_online.png></img>";
}
?>


Que es lo que hace? Esto hace una consulta a la base de datos y me dice si un usuario esta conectado.
Bueno, cuando el usuario esta conectado, aparece que esta conectado.
Cuando esta desconectado no aparece nada.


Entonces probe modificandole y poniendole la variable ELSE.

Quedaria asi:


Código PHP:
<?php
$link 
mysql_connect("localhost""root""******");
mysql_select_db("forum",$link);
$sql "select * from session where userid ='".mysql_escape_string($_POST['caja1'])."'";
$sql mysql_query($sql) or die(mysql_error());  
while(
$row mysql_fetch_array($sql))
{
echo 
"<b>Conectado</b><img src=images/user_online.png></img>";
}
else

echo 
"<b>Desconectado</b><img src=images/user-offline.png></img>"
}
?>


Pero cuando guardo el archivo PHP e ingreso al archivo por el Browser (Firefox, IE, Chrome) me sale este error:



Parse error: syntax error, unexpected T_ELSE in C:\AppServ\www\foro\on.php on line 39



A que se debe esto?

Desde ya, Gracias.


Saludos.
vBulletin Argentina.