Duda sistema de usuarios

Iniciado por deth, Febrero 08, 2015, 11:34:04 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Febrero 08, 2015, 11:34:04 AM Ultima modificación: Febrero 08, 2015, 12:55:13 PM por Expermicid
hola amigos como hago para que le salga una tabla diferente a cada usuario que ingrese a mi sistema de libreria y pueda ingresar sus datos y no se confundan esos datos con los de los demas usuarios?

aqui va mi codigo:

registrar.php

Código: php
    <?php
    session_start();
    mysql_connect('localhost','root','123456')or die ('Ha fallado la conexión: '.mysql_error());
    mysql_select_db('mi_base')or die ('Error al seleccionar la base de datos: '.mysql_error());
    function formRegistro(){
    ?>
    <title>Registrar</title>
    <body style="background-color: #f4f4f4">
    <form action="registrar.php" method="post">
    Usuario (max 20):
     <input type="text" name="username" size="20" maxlength="20" style="width: 105px" /><br />
    Clave (max 10):
    <input type="password" name="password" size="10" maxlength="10" />
    <br>Confirma: <input type="password" name="password2" size="10" maxlength="10" /><br><br />
    <input type="submit" value="Registrar" style="height: 24px" /> <br>
    <br> 
    <input type="button" onclick="window.location='http://localhost/libreria/index2.php';" value="Regresar" / style="width: 77px; height: 26px"/></td>
    </form>
    <?php
    }
    if (isset($_POST["username"])) {
    $username = $_POST["username"];
    $password = $_POST["password"];
    $password2 = $_POST["password2"];
    if($username==NULL|$password==NULL|$password2==NULL) {
    echo "un campo está vacio.";
    formRegistro();
    }else{
     
    if($password!=$password2) {
    echo "Las contraseñas no coinciden";
    formRegistro();
    }else{
     
    $checkuser = mysql_query("SELECT usuario FROM usuarios WHERE usuario='$username'");
    $username_exist = mysql_num_rows($checkuser);
     
    if ($username_exist>0) {
    echo "El nombre de usuario ya esta en uso";
    formRegistro();
    }else{
    $query = 'INSERT INTO usuarios (usuario, password)
    VALUES (\''.$username.'\',\''.$password.'\')';
    mysql_query($query) or die(mysql_error());
    echo 'El usuario '.$username.' ha sido registrado de manera satisfactoria.<br />';
    echo 'Ahora puede entrar ingresando su usuario y su clave. <br />';
    ?>
    <body style="background-color: #f4f4f4">
    <br> 
    <input type="button" onclick="window.location='http://localhost/libreria/index2.php';" value="Regresar" / style="width: 77px; height: 26px"/></td>
     
               <?php
            }
         }
      }
    }else{
      formRegistro();
    }
    ?>
     


login.html
Código: html5
<!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">

<head>
  <title>Área Restringida</title>
  <form action="validar.php" method="post">
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="estilo2.css" type="text/css" />
</head>
<body>

<div class="wrapper">

<form class="validar.php" method="post">&nbsp;<div class="formtitle" style="width: 518px">
Área Restringida</div>

<div class="input" style="width: 519px">
<div class="inputtext">Usuario: </div>
<div class="inputcontent">

<input type="usuario" name="usuario" />

</div>
</div>

<div class="input nobottomborder" style="width: 520px">
<div class="inputtext">Clave: </div>
<div class="inputcontent">

<input type="password" name="password" />
<br/>&nbsp;</div>
</div>

<div class="buttons" style="width: 508px">

<input class="orangebutton" type="submit" value="Ingresar" style="width: 104px; height: 38px" />

<input class="greybutton" type="button" onclick="window.location='http://localhost/libreria/index.html';"  value="Regresar" style="height: 38px" /><div>
</div>


</div>

</form>

<div class="link"></div>

</div>


</body>
</html>


index2.php (aqui es donde debe aparecerle a cada usuario su tabla)
Código: php
    <?php
    session_cache_limiter('nocache');
    session_start();
    ?>
     
    <head>
    <title>Libros</title>
     
    </head>
    <body style="background-color: #f4f4f4">
     
    <?php
    if (isset($_SESSION['k_username'])) {
    echo '<b>Bienvenido '.$_SESSION['k_username'].'</b>';
    echo '<p><a href="logout.php">Salir</a></p>';
         echo '<p><a href="registrar.php">Registrar</a></p>';
    ?>
    <!DOCTYPE html>
    <form method="post">
    <table>
     
    <tr>
    <td>Titulo</td>
    <td><input type="text" name="Titulo" /></td>
    </tr>
    <tr>
    <td>Autor</td>
    <td><input type="text" name="Autor" /></td>
    </tr>
    <tr>
    <td>Editorial</td>
    <td><input type="text" name="name" /></td>
    </tr>
    <tr>
    <td>Año</td>
    <td><input type="text" name="copy" /></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" value="Agregar" /></td>
    </tr>
    </table>
    <?php
    if (isset($_POST['submit']))
    {
    include 'db.php';
     
    $Titulo=$_POST['Titulo'] ;
    $Autor= $_POST['Autor'] ;
    $name=$_POST['name'] ;
    $copy=$_POST['copy'] ;
    mysql_query("ALTER TABLE libros AUTO_INCREMENT=1");
    mysql_query("INSERT INTO `libros`(Titulo,Autor,Editorial,Año)
    VALUES ('$Titulo','$Autor','$name','$copy')");
     
     
           }
    ?>
    </form>
    <table border="1">
     
    <?php
    include("db.php");
     
     
    $result=mysql_query("SELECT * FROM libros");
     
    while($test = mysql_fetch_array($result))
    {
    $id = $test['Número'];
    echo "<tr align='center'>";
    echo"<td><font color='black'>" .$test['Número']."</font></td>";
    echo"<td><font color='black'>" .$test['Titulo']."</font></td>";
    echo"<td><font color='black'>". $test['Autor']. "</font></td>";
    echo"<td><font color='black'>". $test['Editorial']. "</font></td>";
    echo"<td><font color='black'>". $test['Año']. "</font></td>";
    echo"<td> <a href ='view.php?Número=$id'>Editar</a>";
    echo"<td> <a href ='del.php?Número=$id'><center>Eliminar</center></a>";
     
    echo "</tr>";
    }
    mysql_close($conn);
    ?>
    </table>
     
    <p>&nbsp;</p>
     
    </body>
     
     
     
     
     
    <?php
     
    }else{
     
    }
    ?>
     

muchas gracias de antemano.