Member Registration

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rick88
Forum Newbie
Posts: 1
Joined: Wed Dec 08, 2010 4:30 am

Member Registration

Post by rick88 »

Hi I was wondering if anybody might be able to help me with a member registration page I have been having difficulty with. I am new to the language and not sure exactly where I'm going wrong.
I have a mysql database called beat with fields fullname, password and username.
However the page is throwing the following errors on load.
Notice: Undefined index: submit in (filename) on line 4
Notice: Undefined index: filename in (filename) on line 8
Notice: Undefined index: username in (filename) on line 9
Notice: Undefined index: password in (filename) on line 11
Notice: Undefined index: repeatpassword in (filename) on line 12
The page will move to the next on submit and valadation is upheld. However data is not passed to the db.
Any help you could offer would be greatly apreciated.


<?php
echo "<h1>Register</h1>";

$submit = $_POST['submit'];


//form data
$fullname = strip_tags($_POST['fullname']);
$username = strtolower(strip_tags ($_POST['username']));

$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$date = date ("Y-m-d");

if ($submit)
{

//connect to database
$connect = mysql_connect("localhost","root","");
mysql_select_db("beat");//select database

$namecheck = mysql_query ("Select username FROM users where username='$username'");
$count = mysql_num_rows($namecheck);

if ($count!=0)

{

die("Username already exists");
}

//check for existance
if ($fullname&&$username&&$password&&$repeatpassword)
{



if ($password==$repeatpassword)
{
//check char length of username and fullname
if (strlen($username)>25||strlen($fullname)>25)
{
echo "Length of username or fullname is too long";
}

else
{

//check password length
if (strlen($password)>11||strlen($password)<6)
{

echo "Password must be between 6 & 11 characters";
}
else
{



//encrypt password
//$password = md5($password);
//$repeatpassword = md5($repeatpassword);



$queryreg = mysql_query("

Insert INTO users VALUES ('', '$fullname','$username','$password','$date')

");

die("You have been registered. <a href=' index_1.php'>Return to login page</a>");

}

}

}
else
echo "Your passwords do not match";


}
else
echo "Please fill in <b>all</b> fields";

}
?>

<html>
<p>

<form action='register.php' method='POST'>
<table>
<tr>
<td>
Your full name:
</td>
<td>
<input type='text' name='fullname' value='<?php echo $fullname ?>'>
</td>
</tr>
<tr>
<td>
Choose a username:
</td>
<td>
<input type='text' name='username' value='<?php echo $username ?>'>
</td>
</tr>
<tr>
<td>
Choose a password:
</td>
<td>
<input type='password' name='password'>
</td>
</tr>

<tr>
<td>
Repeat Password:
</td>
<td>
<input type='password' name='repeatpassword'>
</td>
</tr>
</table>
<p>
<input type='submit' name='submit' value='Register'>
</form>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Member Registration

Post by social_experiment »

Firstly, if you use php tags your code will be readable. That increases you chances of getting helped. Now that the sermon is over, your INSERT query is incorrect. It should be:

Code: Select all

<?php $queryreg = mysql_query("Insert INTO users (fullname_field, username_field, password_field, date_field) VALUES ('$fullname','$username','$password','$date')"); ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply