View Full Version : Problems with Register Script

05-04-2004, 09:44 PM
what the hell is wrong with this code ??? please help





// set this
$db_host = "localhost";
$db_username = "root";
$db_password = "*******";
$database = "mydb";

// ok always remember this baby ;)

if($_POST['submit']) {

// lets check they didnt leave the god damned things blank
// for future reference
// name = $name = $_POST['name']
// lastname = $lname = $_POST['lname']
// email address = $email = $_POST['email']
// age = $age = $_POST['age']
// username = $user = $_POST['user']
// password = $pass = $_POST['pass'] remember to md5
// signdate = now()

$name = $_POST['name'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$age = $_POST['age'];

// make sure no users typed any characters that they shouldnt have

$name = stripslashes($name);
$lname = stripslashes($lname);
$email = stripslashes($email);
$user = stripslashes($user);
$age = stripslashes($age);

//check if they entered it
if(!$name) {
echo "<font color=\"red\"><b>Please enter your first name</font></b>";
if(!$lname) {
echo "<font color=\"red\"><b>Please enter your last name</font></b>";
if(!$email) {
echo "<font color=\"red\"><b>Please enter your email</font></b>";
if(!$user) {
echo "<font color=\"red\"><b>Please enter a username</font></b>";
if(!$pass) {
echo "<font color=\"red\"><b>Please enter a password</font></b>";

// make the password md5 secure ;)
$monkey = $pass;
$pass = md5($pass);
// see if they already exist
$username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email'");
$norow_username = mysql_num_rows($username_check);
$norow_email = mysql_num_rows($email_check);
if ($norow_username > 0) {
echo "<font color=/"red/"><b>Sorry username already exists :D</b></font>";

if ($norow_email > 0) {
echo "<font color=\"red\"><b>Sorry email address is already registered</b></font>";

// ok lets put it in :D

$conn = mysql_connect($db_host,$db_username,$db_password) or die ("Problems connecting to mysql".mysql_error());
mysql_select_db ($database,$conn) or die ("Could not select database");

// connected!
//oops forgot to register time ;)
$mydate = now();

$queryone = "INSERT INTO users
mysql_query($queryone, $conn);
if(!queryone) {
echo "There has been a error creating your account";
} else {
$userid = mysql_insert_id();
$to = $email;
$subject = "Membership at TiG, $name $lname";
$message = "Dear $name $lname

you have recently signed up at TiG, we thank you for this...
you must click the link below to activate your account thank you

click here: http://tig.deathdragon.net/test/activate.php?id=$userid&code=$pass

if the link does not appear copy the link to your address bar

You signed up with the following information
Username : $user
Password : $monkey

TiG Staff

This is a automatic response please do not reply!";
mail($to, $subject, $message,
"From: TiG\n
X-Mailer: PHP/" . phpversion());

echo "Your membership details have been mailed to the address supplied please follow the instructions in the email";
}else {
<form method=post action="register.php">
<b>First Name* : </b><input type="text" name="name"><br />
<b>Last Name* : </b><input type="text" name="lname"><br />
<b>Email Address*: </b><input type="text" name="email"><br />
<b>Age* : </b><input type="text" name="age"><br />
<b>Username* : </b><input type="text" name="user"><br />
<b>Password* : </b><input type="text" name="pass"><br />
<input type="submit" name="submit"><br>
<b>* = Required</b>



I just get a blank screen , argh :)

05-04-2004, 10:35 PM
just a quick look revealed that your checking username and email with a mysql query and you havent connected to the database untill further into the script

05-04-2004, 10:47 PM
line 83 " escaped with / sould be \

line 23 sould be
if(isset($_POST['submit'])) {

lines 36 to 49 could be shortened like so
$name = stripslashes($_POST['name']);

line 78 reffers to $username which dosent exsist

and you might want to add
error_reporting(E_ALL); to the start of you script so you can see any error messages, remove it once development is done

05-05-2004, 12:02 AM
Hi ASPdude, a couple of things to consider next time you post:

Your post title should be descriptive of what you are attempting to do... I will change the thread title to "Problems with Register Script"
The wording in your post was not extremely helpful... "why the hell wont this work" isn't really the best thing to say... You could say what you have tried and give some more in depth information.

I understand that you are new here, so I wont go on and on, but please consider reading our posting guidelines at http://www.codingforums.com/postguide.htm

05-05-2004, 09:49 PM
ok a few things : I thought the 'isset' function was optional. ??? :: What does that error thing do ??

thank you for all your help ;) and sorry bout all the bad grammer topics and comments ;)

05-05-2004, 09:54 PM
while the script is still likley to function without the isset, it should always be used to check the presence of a variable... On systems with higher error reporting, if you check a variable without isset, you will get an error.

The error reporting section, which has E_ALL within it, turns up error reporting to display all errors... If you dont use isset here you will get errors. It is always a good idea to have error reporting set to E_ALL for testing so you can see all errors as they happen.