Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/05/2011, 14:14
Avatar de carlosmderio3
carlosmderio3
 
Fecha de Ingreso: marzo-2011
Ubicación: valencia
Mensajes: 67
Antigüedad: 14 años
Puntos: 0
sistema de usuarios php mysql incompleto

hola, tengo un codigo php de registro de usuarios, pero necesito que se coloquen mas datos en la db, si que deje de funcionar el script.

ya que antes he metido mis manos y lo he fastidiado varias veces con manual y sin manual... es que no entiendo muy bien...

van los codigos:


Código PHP:
CREATE TABLE IF NOT EXISTS `members` (
  `
idint(11NOT NULL auto_increment,
  `
usernamevarchar(255NOT NULL,
  `
passwordvarchar(255NOT NULL,
  `
emailvarchar(255NOT NULL,
  `
ipvarchar(255NOT NULL,
  `
datevarchar(255NOT NULL,
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM AUTO_INCREMENT=
config.php

Código PHP:
<? ob_start(); session_start();
$db_host "localhost";
$db_username " root";  
$db_password " clave_root";
$db_name " registros";
mysql_connect ("".$db_host."""".$db_username."","".$db_password."") or die('Cannot connect to the database because: ' mysql_error());
mysql_select_db ("".$db_name."");
$site_name "Usuarios";
$site_email "[email protected]";
?>


login.php


Código PHP:
<? ob_start();session_start();include_once"config.php";
if(isset(
$_SESSION['username']) || isset($_SESSION['password'])){
    
header("Location: membersarea.php");
}else{
if(isset(
$_POST['login'])){
$usernametrim($_POST['username']);
$password trim($_POST['password']);
if(
$username == NULL OR $password == NULL){
$final_report.="Please complete all the fields below..";
}else{
$check_user_data mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error());
if(
mysql_num_rows($check_user_data) == 0){
$final_report.="This username does not exist..";
}else{
$get_user_data mysql_fetch_array($check_user_data);
if(
$get_user_data['password'] != $password){
$final_report.="Your password is incorrect!";
}else{
$start_idsess $_SESSION['username'] = "".$get_user_data['username']."";
$start_passsess $_SESSION['password'] = "".$get_user_data['password']."";
$final_report.="You are about to be logged in, please wait a few moments.. <meta http-equiv='Refresh' content='2; URL=membersarea.php'/>";
}}}}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>

</head>
<body>
<form action="" method="post">
  <table width="400" align="center" cellpadding="2" cellspacing="2">
    <tr>
      <td colspan="2" align="center" bgcolor="#0066CC" class="bglink">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="center" class="title">.</td>
    </tr>
    <tr>
      <td colspan="2"><? if(!isset($_POST['login'])){?>
        Please use your username and password to login.
        <? }else{ echo "".$final_report."";}?></td>
    </tr>
    <tr>
      <td width="120">Username:</td>
      <td width="180"><input type="text" name="username" size="30" maxlength="25"></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><input type="password" name="password" size="30" maxlength="25"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="login" value="Login" /></td>
    </tr>
    <tr>
      <td colspan="2" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="center" bgcolor="#0066CC" class="bglink"><a href="register.php">Register</a> - <a href="lostpassword.php">Lost Password</a></td>
    </tr>
    </tr>
  </table>
</form>
</body>
</html>

settings.php

Código PHP:
<? ob_start(); session_start();include_once"config.php";
if(!isset(
$_SESSION['username']) || !isset($_SESSION['password'])){
    
header("Location: login.php");
}else{
$user_data "".$_SESSION['username']."";
$fetch_users_data mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE `username`='".$user_data."'"));
}
if(isset(
$_POST['update'])){
$oldp $_POST['oldpass'];
$newp $_POST['newpass'];
$conp $_POST['conpass'];
if(
$oldp == NULL OR $newp == NULL OR $conp == NULL){
$final_report.="Please complete all the form fields!";
}else{
$check_pass mysql_query("SELECT * FROM `members` WHERE `username`='".$user_data."'");
$check_data mysql_fetch_array($check_pass);
if(
$check_data['password'] != $oldp){
$final_report.="Your old password does not match the database!";
}else{
if(
strlen($newp) <= || strlen($newp) >= 12){
$final_report.="Your password must be between 6 and 12 digits and characters!";
}else{
if(
$newp != $conp){
$final_report.="The confirmed password does not match your new password!";
}else{
$update_pass mysql_query("UPDATE `members` SET `password` = '$newp' WHERE `username` = '".$user_data."' LIMIT 1");
$final_report.="Your password has been changed, you will need to login again.";
@
session_destroy(); 
header'refresh: 3; url=login.php');
}}}}}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form method="post">
  <table width="700" border="0" align="center" cellpadding="0" cellspacing="2">
    <tr>
      <td height="30" colspan="2" class="title">&nbsp;</td>
    </tr>
    <tr>
      <td width="170" bgcolor="#0066CC" class="header">&nbsp;Members Menu</td>
      <td width="524" bgcolor="#0066CC" class="header">&nbsp;Settings</td>
    </tr>
    <tr>
      <td valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td><a href="membersarea.php">Members Area</a> </td>
          </tr>
          <tr>
            <td><a href="settings.php">Settings</a></td>
          </tr>
          <tr>
            <td><a href="logout.php">Logout</a></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      <td valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td colspan="2"><? if(!isset($_POST['update'])){ echo "".$user_data."";?>, this is where you can update your password, just enter your old and new password below and then click on the  apply changes button.
              <? }else{
        echo
"".$final_report."";
        
        }
?></td>
          </tr>
          <tr>
            <td width="42%">Old Password: </td>
            <td width="58%"><input name="oldpass" type="password" id="oldpass"></td>
          </tr>
          <tr>
            <td>New Password: </td>
            <td><input name="newpass" type="password" id="newpass"></td>
          </tr>
          <tr>
            <td>Confirm Password: </td>
            <td><input name="conpass" type="password" id="conpass"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input name="update" type="submit" id="update" value="Apply Changes"></td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td height="16" colspan="2" align="center" valign="top" bgcolor="#0066CC">&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
register.php


Código PHP:
<? include_once"config.php";
if(isset(
$_SESSION['username']) || isset($_SESSION['password'])){
    
header("Location: membersarea.php");
}else{
if(isset(
$_POST['register'])){
$username $_POST['username'];
$password $_POST['password'];
$email $_POST['email'];
$memip $_SERVER['REMOTE_ADDR'];
$date date("d-m-Y");
if(
$username == NULL OR $password == NULL OR $email == NULL){
$final_report.= "Please complete the form below! Try again.";
}else{
if(
strlen($username) <= || strlen($username) >= 31){
$final_report.="Your username must be between 3 and 30 characters! Try again.";
}else{
$check_members mysql_query("SELECT * FROM `members` WHERE `username` = '$username'");   
if(
mysql_num_rows($check_members) != 0){
$final_report.="The username is already in use! Try again."
}else{ 
if(
strlen($password) <= || strlen($password) >= 12){
$final_report.="Your password must be between 6 and 12 digits and characters! Try again.";
}else{
if(!
eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$email)){ 
$final_report.="Your email address was not valid! Try again.";
}else{
$create_member mysql_query("INSERT INTO `members` (`id`,`username`, `password`, `email`, `ip`, `date`) 
VALUES('','$username','$password','$email','$memip','$date')"
); 
$final_report.='Thank you for registering, you may <a href="login.php">login here</a>.'
}}}}}}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>
<body>
<form method="post">
  <table width="400" border="0" align="center" cellpadding="2" cellspacing="2">
    <tr>
      <td colspan="2" bgcolor="#0066CC">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="center" class="title"></td>
    </tr>
    <tr>
      <td colspan="2"><? if(!isset($_POST['register'])){?>
        Complete the form below to create your account.
        <? }else{ echo "".$final_report."";}?></td>
    </tr>
    <tr>
      <td width="37%">Username:</td>
<input name="username" type="text" id="username" size="30" />
Password:
      <td><input name="password" type="password" id="password" value="" size="30" />

      <td>Email:</td>
<input name="email" type="text" id="email" size="30" />
    <input name="register" type="submit" id="register" value="Register" />
</form>
bueno, nose que modificar, asi que les dejo el codigo...
esto es lo que pretendo gracias....
Pagina de perfil:
Usuario:
nombre
apellido
clave:
mail:
edad: con <select>
ciudad:
pais:
DNI
direccion:
telefono:
movil:
etc:
registro.php
usuario:
Nombre:
Apellido:
email:

login.php
usuario:
mail:
__________________
Oir EuropaFM Valencia!