Results 1 to 8 of 8

Thread: Problem regarding user registration.

  1. #1
    Join Date
    Sep 2007
    Posts
    172
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Problem regarding user registration.

    I have created a MYSQL database and a form on dreamweaver with all the fields I have mentioned in database but what I have to do to make people register with the form I mean to say if a person fill the form and click on submit OR register how can all the data will go in database I have created?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You would need a server side code (php, asp, etc) to process the form data and insert in the database. http://www.php-mysql-tutorial.com has some good tutorials on this.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Sep 2007
    Posts
    172
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    I know this site but I think this is not mentioned in this tutorial about server side code where can I have that code?

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    You have to actually make it
    That's why it's called... a "TUTORIAL".

    Edit:

    Here's a simple login script that I made:

    1. Save this as login.php
    PHP Code:
    <?php
    session_start
    ();

    $dbuser ''//Database Username
    $dbpass ''//Database Password
    $dbhost ''//Database Host
    $db ''//Database

    mysql_connect($dbhost$dbuser$dbpass) or die(mysql_error());
    mysql_select_db($db);

    /* PLEASE REMOVE THIS AFTER YOU HAVE RUN ?setup=true */

    if (isset($_GET['setup']))    {

    $sql 'CREATE TABLE `users` (`user` TEXT NOT NULL, `pass` TEXT NOT NULL, `email` TEXT NOT NULL) ENGINE = InnoDB';
    mysql_query($sql) or die(mysql_error());
    echo 
    'Table created. Remember to remove the ?setup part in the source page.';
    die();
    }

    /* PLEASE REMOVE THIS PART AFTER YOU HAVE RUN ?setup=true */

    $errMsg 'Please enter your username and password to begin.';
    $showForm=1;

    if (isset(
    $_GET['register']))    {
        
    $errMsg 'Register here...';
    }

    if (isset(
    $_SESSION['errMsg']))    {
        
    $errMsg $_SESSION['errMsg'];
        unset(
    $_SESSION['errMsg']);
    }
    if (isset(
    $_POST['Login']))    {
        
    $user $_POST['user'];
        
    $pass md5(md5(md5($_POST['pass'])));
        
        
    $sql "SELECT * FROM `users` WHERE user='$user' AND pass='$pass'";
        
    $result mysql_query($sql);
        
    $row mysql_fetch_assoc($result);
        if (
    $row['pass'] == $pass && $row['user'] == $user)    {
            
    $errMsg 'Thanks for logging in!';
            
    $ip $_SERVER['REMOTE_ADDR'];
            
    $ip substr($ip,0,strrpos($ip,'.'));
            
    $_SESSION['logged'] = $row['user'];
            
    $_SESSION['pass'] = $row['pass'];
            
    $_SESSION['auth'] = md5($row['user'].$row['pass'].$ip);
            
    header('location:'.$_SERVER['PHP_SELF']);
        }
        else    {
            
    $errMsg 'Incorrect username/password.';
        }
    }
    elseif (isset(
    $_POST['Register']))    {
        
    $user $_POST['user'];
        
    $pass md5(md5(md5($_POST['pass'])));
        
    $passco md5(md5(md5($_POST['pass-confirm'])));
        
    $email $_POST['email'];
        
        
    $sql "SELECT * FROM `users` WHERE user='$user'";
        
    $row mysql_query($sql);
        
        if (
    mysql_num_rows($row) != 0)    {
            
    $errMsg 'User taken. You can login now using the form below.';
        }
        elseif (
    $pass != $passco)    {
            
    $errMsg 'Passwords don\'t match.';
        }
        
    //ereg pattern thanks to http://www.ilovejackdaniels.com/php/email-address-validation
        
    elseif (!ereg('^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9](.[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])+$',$email))    {
            
    $errMsg 'You haven\'t provided us with a valid email address.';
        }
        else    {
            
    $sql "INSERT INTO `users`(user,pass,email) VALUES('$user','$pass','$email')";
            
    mysql_query($sql) or die(mysql_error());
            
    $_SESSION['errMsg'] = 'User created.';
            
    $showForm=0;
            
    header('location:'.$_SERVER['PHP_SELF']);
        }
    }

    if (isset(
    $_GET['logout']))    {
        
    session_destroy(); //Destroys the session, aka. all data in the $_SESSION array, eg. username, password etc.
        
    session_start(); //Starts the session all over again
        
    $errMsg 'You have been logged out.';
    }
    //Sets the user
    $user = isset($_SESSION['logged']) ? $_SESSION['logged'] : '';
    //Sets the pass
    $pass = isset($_SESSION['pass']) ? $_SESSION['pass'] : '';
    //Checks if the user is logged in and on the same computer...
    $ip $_SERVER['REMOTE_ADDR'];
    $ip substr($ip,0,strrpos($ip,'.'));
    if (!isset(
    $_SESSION['logged']) || md5($user.$pass.$ip) != $_SESSION['auth'])    {
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Login</title>
    </head>

    <body>
    <?php
    if (isset($_GET['register']))    {
    echo 
    $errMsg;
    if (
    $showForm!=0)    {
    ?>

    <form name="register" method="post" action="?register=true">
        <p>
          <label>Username: <input type="text" name="user" value="<?php echo isset($_POST['user']) ? $_POST['user'] : ''?>"></label>
        </p>
        <p>
          <label>Password: <input type="password" name="pass"></label>
        </p>
        <p>
          <label>and again: <input type="password" name="pass-confirm"></label>
        <p>
        <p>
          <label>E-Mail: <input type="text" name="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''?>"></label>
        </p>
        <p>
          <label><input type="submit" name="Register" value="Register"></label>
        </p>
    </form>

    <?php
    }
    } else    {
    echo 
    $errMsg// Echoes the error message.
    ?>
    <form name="login" method="post" action="">
        <p>
          <label>Username: <input type="text" name="user"></label>
        </p>
        <p>
          <label>Password: <input type="password" name="pass"></label>
        </p>
        <p>
          <label><input type="submit" name="Login" value="Login"></label>
        </p>
        <p><a href="?register=true">Register</a></p>
    </form>
    <?php ?>
    </body>
    </html>
    <?php
    die(); //Stops outputting anything else.
    }
    ?>
    2. In the pages you want to be secure, put this in:
    PHP Code:
    <?php include('login.php'); ?>
    It'll display the login form when a person isn't logged in.

    3. Goto: login.php?setup=true after you have configured your database stuff in the code

    4. Remove the section where it tells you to.

    5. Try registering/logging in.
    Last edited by tech_support; 10-12-2007 at 12:30 AM.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Sep 2007
    Posts
    172
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Oh thank you so much!

  6. #6
    Join Date
    Apr 2007
    Posts
    149
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hello... can anyone tell me what are the advantages of having a user registration... and what services can you offer to those who register? (the most common services...) Thanks

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by remp View Post
    Hello... can anyone tell me what are the advantages of having a user registration... and what services can you offer to those who register? (the most common services...) Thanks
    you can offer anything and/or everything, however any time you need to store information beyond just a session, a database should be used.

    Usually a tier system is a good idea, where you give a global version of the site that anyone can view, a free version where people can register and may contain some proprietary / sensitive information and/or paid version, which is based upon a user giving money to the site (eg donation, monthly payment, yearly payment, etc...)

    basically it just depends on how you want to construct your site and what privileges you would like your users to have.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    User registration allows you some idea of who a visitor is, and how they acquired an account. Is it paid? Is it free? Do you store their email? Credit card? Social security number? Username? IP?

    It allows:
    Identification (such as posting on a forum)
    Limited access / Modified access / Full access (as described above)
    Security to some degree (such as admins who can upload files)
    Contact options (email, PM)
    Data storage/retrieval (very important, and many many uses)
    [indirectly] Connectivity between users, beyond what just an IP can offer
    Tracking (for security, hackers, or even malicious information gathering)
    A feeling of security for the user (whether or not it actually means something)


    To summarize: Storage, Identification, Security/Access.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •