Hi guys I'm trying to fix my user registration page, I've gotten myself into a real mess here so any help would be appreciated
I am getting "Notice: Undefined index" message for my variables (firstname,lastname,password,repeatpasswords) and it is not loading the page only the "die" message which is happening because the script is failing.
<?php
session_start();
$con = mysql_connect('localhost','root','abc');
if (!$con)
{
die ("Could not connect to database" . mysql_error());
}
//get data from the form
if (isset($_POST['firstname'])) { $firstname = $_POST['firstname']; }
if (isset($_POST['lastname'])) { $lastname = $_POST['lastname']; }
if (isset($_POST['username'])) { $username = $_POST['username']; }
if (isset($_POST['password'])) { $password = $_POST['password']; }
if (isset($_POST['repeatpassword'])) { $repeatpassword = $_POST['repeatpassword']; }
if (isset($_POST['submit']))
{
//check for existance
if ($firstname&&$lastname&&$username&&$password&&$repeatpassword)
{
//check passwords match
if ($password==$repeatpassword)
{
//check char length of username and names
if (strlen($username)>25||strlen($firstname)>25)
{
echo "The first name, last name or username fields are too long!";
}
else
{
//check password length
if (strlen($password)>25||strlen($password)<6)
{
echo "Password must be between 6 and 25characters";
}
else
{
//encrypt password
$password = md5 ($password);
$repeatpassword = md5 ($repeatpassword);
}
}
}
else
echo "Your passwords do not match!";
}
else
echo "Please fill in all fields!";
}
//select database table
mysql_select_db('theimageworks');
//add data to database
$sql="INSERT INTO user (firstname, lastname, username, password)
VALUES ('$_POST[firstname]', '$_POST[lastname]', '$_POST[username]', '$_POST[password]')";
if (!mysql_query($sql,$con))
{
die ('Error: ' . mysql_error());
}
die ("You have been registered! Return to <a href='loginpage.php'>login page</a>");
mysql_close($con);
?>