Sin entrar mucho en el código, tienes dos problemillas, faltan dos } y cierras la conexión antes de terminar el primer while:
Código PHP:
<?php
$con = mysql_connect("server","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("nombre_base", $con);
$result = mysql_query("SELECT count(*) AS cuenta, password FROM usuario WHERE username='$_POST[usuario]'");
while($row = mysql_fetch_array($result))
{
$crypted = md5($_POST["clv"]);
if ($row['cuenta']==1 && $row["password"] == $crypted ){
session_start("autentificado", "usuario", "nombre", "apellido1");
$_SESSION["autentificado"]= "SI";
$_SESSION["usuario"] = $_POST["usuario"];
$result = mysql_query("SELECT usr_id, username, nombre, apellido1, apellido2, tipo_perfil_id
FROM usuario
WHERE username='$_POST[usuario]';");
//echo "<table border='0' align='center'>";
while($row = mysql_fetch_array($result))
{
$_SESSION["nombre"] = $row["nombre"];
$_SESSION["apellido1"] = $row["apellido1"];
$redir = ".index2.html?usr=" . $row['usr_id'] . "&tp=" . $row['tipo_perfil_id'];
header("Location: $redir");
if ($row['cuenta']==54 && $row["password"] == $crypted ){
session_start("autentificado", "usuario", "nombre", "apellido1");
$_SESSION["autentificado"]= "SI";
$_SESSION["usuario"] = $_POST["usuario"];
$result = mysql_query("SELECT usr_id, username, nombre, apellido1, apellido2, tipo_perfil_id
FROM usuario
WHERE username='$_POST[usuario]';");
//echo "<table border='0' align='center'>";
while($row = mysql_fetch_array($result))
{
$_SESSION["nombre"] = $row["nombre"];
$_SESSION["apellido1"] = $row["apellido1"];
$redir2 = ".index1.html?usr=" . $row['usr_id'] . "&tp=" . $row['tipo_perfil_id'];
header("Location: $redir2");
}
} else {
echo "<br><br><br><br><br><br><br><br><br><br><br>" ;
echo "<table border='0' align='center'>
<tr>
<th><h1> Su usuario no ha sido aceptado*" . $_POST[usuario] . "*</h1></th>
</tr>
<tr>
<th> <A href='aviso.html'> Intentar nuevamente </A>
</tr></table>";
}
}
}
}
mysql_close($con);
?>
A ver si te sirve para empezar, saludos