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` (
  `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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

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

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

Now create registration script called "register.php".

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

//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' );";


header('Location: login.php');

Hope it help you.


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

what's this op means?????


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


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].


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.