Re: Creating a registration page with php and mysql
Thanks for the quick reply, wasn't expecting that!
And i don't want a login script sorry for the misunderstanding. This is what i mean ill give you the html and the php i have so far.
<form name="register" method="post" action="#">
<div class="box">
<label for="firstname">First Name:*</label>
<br />
<input type="text" name="firstname" id="firstname" maxlength="30" class="text" />
</div>
<div class="box">
<label for="lastname">Last Name:*</label>
<br />
<input type="text" name="lastname" id="lastname" maxlength="30" class="text" />
</div>
<div class="box">
<label for="username">Username:*</label>
<br />
<input type="text" name="username" id="username" maxlength="20" class="text" />
<sub><i>(4-20 Characters)</i></sub>
</div>
<div class="box">
<label for="password">Password:*</label>
<br />
<input type="password" name="password" id="password" maxlength="10" class="password" />
<sub><i>(6-10 Characters)</i></sub>
</div>
<div class="box">
<label for="confirmpassword">Confirm Password:*</label>
<br />
<input type="password" name="confirmpassword" id="confirmpassword" maxlength="10" class="password" />
<sub><i>(6-10 Characters)</i></sub>
</div>
<div class="box">
<label for="email">Email:*</label>
<br />
<input type="text" name="email" id="email" maxlength="60" class="text" />
</div>
<div class="box">
<label for="confirmemail">Confirm Email:*</label>
<br />
<input type="text" name="confirmemail" id="confirmemail" maxlength="60" class="text" />
</div>
<hr />
<div class="box">
<center>
<iframe src="The_agreement" scrolling="yes" frameborder="no" height="600px" width="500px" class="agreement" id="agreement"></iframe>
<br />
<label for="agree">I Agree</label>
<br />
Yes<input type="radio" name="agree" id="agree" />
No<input type="radio" name="agree" id="agree" />
</center>
</div>
<div class="box">
<center>
<input type="reset" name="Start Over" value="Start Over" class="reset"></input>
<input type="submit" name="submit" value="Join us!" class="submit">
</form>
The PhP i am using is
<?php
include("dbconnect");
$errors = "";
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$email = $_POST['email'];
$confirmemail = $_POST['confirmemail'];
$usernamecheck = mysql_query("SELECT * FROM members WHERE username = '$username'");
$emailcheck = mysql_query("SELECT * FROM members WHERE email = '$email'");
$date = date('n-j-y');
$validate_key = md5(time()+rand(1000,100000).$username);
$message="My Message"
if (!isset($firstname))
$errors .="You have not provided your <b>First Name</b>.<br />";
if (!isset($lastname))
$errors .="You have not provided your <b>Last Name</b>.<br />";
if (!isset($username))
$errors .="You have not provided a <b>Username</b>.<br />";
if (!isset($password))
$errors .="You have not provided a <b>Password</b>.<br />";
if ($password != $confirmpassword)
$errors .="Your <b>Passwords</b> do not match.<br />";
if (!isset($email))
$errors .="You have not provided an <b>Email Address</b>.<br />";
if ($email != $confirmemail)
$errors .="Your <b>Emails</b> do not match.<br />";
if (strlen($username) < 4 )
$errors .="Your <b>Username</b> is too small.<br />";
if (strlen($username) > 20 )
$errors .="Your <b>Username</b> is too long.<br />";
if (strlen($password) < 6 )
$errors .="Your <b>Password</b> is too small.<br />";
if (strlen($password) > 10 )
$errors .="Your <b>Password</b> is too long.<br />";
if (mysql_num_rows($usernamecheck)==1)
$errors .="Sorry but the username <b>$username</b> is already taken.<br />";
if (mysql_num_rows($emailcheck)==1)
$errors .="Sorry but the email <b>$email</b> is already taken.<br />";
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
$errors .="<b>$email</b> is an invalid email address.<br />";
if ($errors == "") {
$firstname = addslashes($firstname);
$lastname = addslashes($lastname);
$username = addslashes($username);
$password = md5($password);
$date = date('n-j-y');
$email = addslashes($email);
$usergroup = 1;
$validcode = md5(time()+rand(1000,100000).$username);
mysql_query("INSERT INTO members VALUES(
'',
'$firstname',
'$lastname',
'$username',
'$password',
'$email',
'$date',
'$usergroup',
'$validcode')");
mysql_close();
mail($email,"Validate Your Account",$message);
?>
and then of course i have the else....
As you can see im using "If" for about everything..Is this acceptable or am i doing this wrong? and also how would i make the php code for the users input of a radio, (yes or no) and a select (optgroup) and finally how can i create the validation page to confirm the registration!
No its not Fowbers its foobers :D