Show logged-in user reservations only

0

I wanted to know how I can show only reservations made by the logged-in user, as I tried a lot of code and none of them worked. I tried declaring a session with the ID, which I even picked up but displayed information from another user.

Remembering that I can book with name, surname, email and phone.

<?php
session_start();
if($_SESSION['nivel'] == "usuario"){}else{


    header("Location:../login.php");
exit;

}

include "php/conexao.php";

$query = mysql_query ("SELECT * FROM cadastro WHERE username = '{$_SESSION['username']}' AND id='{$_SESSION['id']}' AND senha = '{$_SESSION['senha']}'") or die(mysql_error());
$usuario = mysql_fetch_assoc($query);

?>

                                            

<body>

    <!-- header -->
    <header id="header">
        <h2>Painel administrativo</h2>
    </header>

    <!-- sidebar -->
    <aside id="sidebar">
        <div class="links">
            <h2><?php echo $usuario['username']; ?></h2>
        </div>
        <div class="links"><div style="cursor: pointer;"><a onclick="mostra('conta');">Conta</a></div></div>
        <div class="links"><div style="cursor: pointer;"><a onclick="mostra('reserva');">Reserva</a></div></div>
        <div class="links"><a href="php/logout.php">Sair</a></div>
    </aside>

    <!-- conteudo -->
    <div id="content">

        <div id="conta">

            <div class="tabela">
                <table width="100%" border="1">
                <tr>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Nome:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">E-mail:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Telefone</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Mensagem:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Data:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Editar:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Excluir:</td>
                </tr>

                <?php
                $query = mysql_query("SELECT * FROM cadastro WHERE username ='{$_SESSION['username']}'");
                while ($linha = mysql_fetch_array ($query)){

                ?> <!-- esse é para exibir as informações da conta; funciona normalmente -->

                <tr>
                    <td height="45" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $linha ['nome']?></td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $linha ['email']?></td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $linha ['username']?></td>

                    <td align="center" valign="middle" bgcolor="#FFFFFF"><a href="formeditclientes.php?username=<?php echo $linha ['username']?>"></a></td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF"><a href="eliminar.php?username=<?php echo $linha ['username']?>"></a></td>
                </tr>
                <?php

                }
                ?>
                </table>
            </div>
        </div>

        <div id="reserva" style="display:none;">

            <div class="tabela">
                <table width="100%" border="1">
                <tr>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Nome:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">E-mail:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Telefone</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Mensagem:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Data:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Editar:</td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF">Excluir:</td>
                </tr>

                <?php
                $query = mysql_query("SELECT * FROM reserva");
                while ($linha = mysql_fetch_array ($query)){

                ?> <!-- esse é o da reserva; que eu editei agora para aparecer todos, mas que eu gostaria que mostrasse apenas a do usuário logado -->

                <tr>
                    <td height="45" align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $linha ['nome']?></td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $linha ['email']?></td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF"><?php echo $linha ['telefone']?></td>

                    <td align="center" valign="middle" bgcolor="#FFFFFF"><a href="editar_reserva.php?id=<?php echo $linha ['id']?>"></a></td>
                    <td align="center" valign="middle" bgcolor="#FFFFFF"><a href="eliminar_reserva.php?id=<?php echo $linha ['id']?>"></a></td>
                </tr>
                <?php

                }
                ?>
                </table>
            </div>

        </div>

    </div>
</body>

<script>
    function mostra(theId){
        var theArray= new Array('conta', 'reserva');
        w=document.getElementById(theId)
        if(w.style.display=="block"){}else{ 



            for(i=0; i<theArray.length; i++){
                    if(theArray[i] == theId){
                        w.style.display='block';
                    }else{
                        document.getElementById(theArray[i]).style.display='none';
                    }
            }
            }

    }
</script>

    
asked by anonymous 08.11.2018 / 21:17

0 answers