Go Back   Dynamic Drive Forums > General Coding > Other
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-11-2007, 11:42 PM
bbilal bbilal is offline
Junior Coders
 
Join Date: Sep 2007
Posts: 97
Thanks: 3
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?
Reply With Quote
  #2  
Old 10-11-2007, 11:44 PM
thetestingsite's Avatar
thetestingsite thetestingsite is offline
The Guy That Moderates
 
Join Date: Sep 2006
Location: St. George, UT
Posts: 2,795
Thanks: 3
Thanked 156 Times in 154 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
The Testing Site | Atomic Yeti
Reply With Quote
  #3  
Old 10-11-2007, 11:48 PM
bbilal bbilal is offline
Junior Coders
 
Join Date: Sep 2007
Posts: 97
Thanks: 3
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?
Reply With Quote
  #4  
Old 10-12-2007, 12:32 AM
tech_support's Avatar
tech_support tech_support is offline
Modarator Man.
 
Join Date: May 2006
Location: Sydney, Australia - Near the coast.
Posts: 2,011
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.
__________________
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

Last edited by tech_support; 10-12-2007 at 01:30 AM.
Reply With Quote
  #5  
Old 10-12-2007, 08:54 PM
bbilal bbilal is offline
Junior Coders
 
Join Date: Sep 2007
Posts: 97
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Oh thank you so much!
Reply With Quote
  #6  
Old 10-12-2007, 09:03 PM
remp remp is offline
Regular Coders
 
Join Date: Apr 2007
Posts: 106
Thanks: 0
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
Reply With Quote
  #7  
Old 10-12-2007, 09:12 PM
boogyman boogyman is offline
Elite Coders
 
Join Date: Jul 2006
Location: just north of Boston, MA
Posts: 1,789
Thanks: 12
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.
__________________

This is a forum system not a PM system for questions. please treat it appropriately
Reply With Quote
  #8  
Old 10-12-2007, 10:54 PM
djr33's Avatar
djr33 djr33 is online now
Global Moderator
 
Join Date: Mar 2006
Location: N. California, USA
Posts: 6,408
Thanks: 11
Thanked 82 Times in 82 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 - <?php?> | <html>| Ich lerne Deutsch. | Studio l'italiano. | Estudiaba español. | Estudo português. | 日本語の勉強。| मैं हिन्दी सीखो | درس العربية
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:50 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.