I am getting error as
Undefined index: op in C:\wamp\www\testtheme\register.php on line 8
Anybosy knows this error pls let me know.I have uploded file same as above but some errors occured.

Follow this tutorial, I will use mysql as there are still so many wanna be programmers who are using it. But we will sanitize it so it will still look secured.

Let us prepare our database table.

Database name: login
Database table: member

Using phpMyAdmin, create a database called "login".

Now select the database that you have created. Click on the SQL tab and paste the following sql code.

CREATE TABLE `login`.`member` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
  `username` VARCHAR(30) NOT NULL, 
  `password` CHAR(128) NOT NULL, 
  `email` VARCHAR(50) NOT NULL, 
  `salt` CHAR(128) NOT NULL
) ENGINE = InnoDB;

Create a Registration Form called "registration.html". For the meantime let's use table for our design.

<!<!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=utf-8" />
<title>Register</title>
</head>

<body>
<form name="register" action="register.php" method="post">

        <tr>
            <td colspan="2"><p><strong>Registration Form</strong></p></td>
        </tr>
        <tr>
            <td>Username:</td>
            <td><input type="text" name="username" maxlength="20" /></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type="password" name="password1" /></td>
        </tr>
        <tr>
            <td>Confirm Password:</td>
            <td><input type="password" name="password2" /></td>
        </tr>
        <tr>
            <td>Email:</td>
            <td><input type="text" name="email" id="email" /></td>
        </tr>
        <tr>
            <td> </td>
            <td><input type="submit" value="Register" /></td>
        </tr>
    </table>
</form>
</body>
</html>

Now create registration script called "register.php".

First, let us receive the data from our registration form.

<?php
//retrieve our data from POST
$username = $_POST['username'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
$email = $_POST['email'];

if($password1 != $password2)
    header('Location: registration.html');

if(strlen($username) > 30)
    header('Location: registration.html');

    $hash = hash('sha256', $password1);

function createSalt()
{
    $text = md5(uniqid(rand(), true));
    return substr($text, 0, 3);
}

$salt = createSalt();
$password = hash('sha256', $salt . $hash);
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('login', $conn);

//sanitize username
$username = mysql_real_escape_string($username);

$query = "INSERT INTO member ( username, password, email, salt )
        VALUES ( '$username', '$password', '$email', '$salt' );";
mysql_query($query);

mysql_close();

header('Location: login.php');
?>

Hope it help you.

How to create a database with Aptana Studio 3

Notice: Undefined index: op in C:\xampp\htdocs\tut\register.php on line 8

what's this op means?????

this works for me except it says something about op

Notice: Undefined index: op in /opt/lampp/htdocs/login/login.php on line 6
how to solve ?? user not saved in database

Member Avatar for diafol

Do not use these scripts. They are very old and use deprecated functions and unsafe hashing routines. If you want tips about registration / login scripts for PHP, please search this site (in web development), Google (or other search engines), or post a new question in the Web Development forum, tagging it appropriately, e.g. [php login registration mysql].

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.