Show only reservations of the logged-in user

Asked

Viewed 25 times

0

I was wondering how can I show only the reservations made by the logged in user, because I tried a lot of code and none of them worked. I tried declaring a Session with the ID, which even caught, 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>

  • You must have some link in the "reserve" table that identifies you as that user. For example, a field called "usuario_id" in the reserve table.

  • Join...

  • Post the table structure please

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.