Forums
This topic is locked
Setup Login / registration system
Posted 16 Sep 2005 12:30:45
1
has voted
16 Sep 2005 12:30:45 jackie Wong posted:
I want setup login / register system in front of our company intranet site. I using appserv setup mysql server / php.... I have created mysql db and four file login.html / registration.html / login.php / registration.php , but when i test run on dw mx, it does not, . I have enclosed two php code for your review. if found any error, please reply me and correct me. login.php
<?php
//Database Information
$dbhost = "localhost";
$dbname = "registerdb";
$dbuser = "root";
$dbpass = "";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
$query = "select * from users where username='$username'and password=’$password’";
$result = mysql_query($query);
if (mysql_num_rows($result) !=1) {
$error = "Bad Login";
include "login.html";
} else {
$_SESSION[‘username’] = "$username";
include "memberspage.php";
}
?>
registration.php
<?PHP
//Database Information
$dbhost = "localhost";
$dbname = "registerdb";
$dbuser = "root";
$dbpass = "";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
// lets check to see if the username already exists
$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"
$username_exist = mysql_num_rows($checkuser);
if($username_exist > 0){
echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
unset($username);
include 'registration.html';
exit();
}
// lf no errors present with the username
// use a query to insert the data into the database.
$query = "INSERT INTO users (name, email, username, password)
VALUES('$name', '$email', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();
echo "You have successfully Registered";
?>