Help with my "create an account" page - One problem :(

I finally put together enough stuff and had enough help to get this membership system up and working :slight_smile: First problem is that when a member registers, it gives this error:

You did not submit the following required information! — Email Address

Even though I do submit one, I cannot figure out why it wont stay - Any help? Here is the code below for this page.

[php]<?php

$errorMsg = “”;
// First we check to see if the form has been submitted
if (isset($_POST[‘username’])){
//Connect to the database through our include
include_once “/mypersonalsql.php”;
// Filter the posted variables
$username = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘username’]); // filter everything but numbers and letters
$country = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘country’]); // filter everything but spaces, numbers, and letters
$state = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘state’]); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘city’]); // filter everything but spaces, numbers, and letters
$accounttype = ereg_replace("[^a-z]", “”, $_POST[‘accounttype’]); // filter everything but lowercase letters
$email = stripslashes($_POST[‘email’]);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘password’]); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the “Required”(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$username) || (!$country) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password)){

	$errorMsg = "You did not submit the following required information!<br /><br />";
	if(!$username){
		$errorMsg .= "--- User Name";
	} else if(!$country){
		$errorMsg .= "--- Country"; 
	} else if(!$state){ 
	    $errorMsg .= "--- State"; 
   } else if(!$city){ 
       $errorMsg .= "--- City"; 
   } else if(!$accounttype){ 
       $errorMsg .= "--- Account Type"; 
   } else if(!$email){ 
       $errorMsg .= "--- Email Address"; 
   } else if(!$password){ 
       $errorMsg .= "--- Password"; 
   }
} else {
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
$sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check);
$email_check = mysql_num_rows($sql_email_check); 
if ($username_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else if ($email_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
} else {
	// Add MD5 Hash to the password variable
   $hashedPass = md5($password); 
	// Add user info into the database table, claim your fields then values 
	$sql = mysql_query("INSERT INTO members (username, country, state, city, accounttype, email, password, signupdate) 
	VALUES('$username','$country','$state','$city','$accounttype','$email','$hashedPass', now())") or die (mysql_error());
	// Get the inserted ID here to use in the activation email
	$id = mysql_insert_id();
	// Create directory(folder) to hold each user files(pics, MP3s, etc.) 
	mkdir("memberFiles/$id", 0755); 
	// Start assembly of Email Member the activation link
	$to = "$email";
	// Change this to your site admin email
	$from = "[email protected]";
	$subject = "Complete your registration";
	//Begin HTML Email Message where you need to change the activation URL inside
	$message = '<html>
	<body bgcolor="#FFFFFF">
	Hi ' . $username . ',
	<br /><br />
	You must complete this step to activate your account with us.
	<br /><br />
	Please click here to activate now &gt;&gt;
	<a href="http://www.somewebsite.com/activation.php?id=' . $id . '">
	ACTIVATE NOW</a>
	<br /><br />
	Your Login Data is as follows: 
	<br /><br />
	E-mail Address: ' . $email . ' <br />
	Password: ' . $password . ' 
	<br /><br /> 
	Thanks! 
	</body>
	</html>';
	// end of message
	$headers = "From: $from\r\n";
	$headers .= "Content-type: text/html\r\n";
	$to = "$to";
	// Finally send the activation email to the member
	mail($to, $subject, $message, $headers);
	// Then print a message to the browser for the joiner 
	print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />
	We just sent an Activation link to: $email<br /><br />
	<strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
	Link inside the message. After email activation you can log in.";
	exit(); // Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks

} // Close else after missing vars check
} //Close if $_POST
?>

Member Registration
REGISTER AS A MEMBER HERE
<?php echo "$errorMsg"; ?>
User Name:
" />
Country:
"><?php echo "$country"; ?> Australia Canada Mexico United Kingdom United States Zimbabwe
State:
" />
City:
" />
Account Type:
"><?php echo "$accounttype"; ?> Normal User Expert User Super User
Email:
" />
Password:
" /> (letters or numbers only, no spaces no symbols)
Captcha:
Add Captcha Here for security
[/php]

Any help would be greatly appreciated - Thank You!

If anyone has any suggestions I would greatly appreciate it - Thank You :slight_smile:

Well, first, this section: <?php echo "$email"; ?>" is not correct. Once you are “inside” the PHP tags,
you are typing standard PHP code. So, this should be just: <?php echo $email; ?>" In other words,
in PHP if you echo a string such as “$email” it is going to print out $email. It is NOT going to print the
value of the variable named email! So, first you should alter all of these to remove the quotes around
your variable names. This will allow the PHP to print the real value in your HTML input lines.

So, this is one of the most often found errors. In ANY type of web programming, you must use quotes
or double-quotes correctly. You can use “something’something-else’something”… This is an outside
quotes with inside single quotes. You can NOT do “somethings"something-else"something”… This is an
outside quotes with extra ones inside. That would mean it would be broken up something like this:
“something” … something-else … “something” Not what was wanted.

I would start with that and ask any further questions. Also, repost your new code for us to see. Good luck!

Thank you so much! Let me go ahead and adjust this and I will update you shortly :slight_smile:

Thanks again for the information; however, it did not fix my problem :frowning: Here is my new code as you requested:

[php]<?php
/*
Created By Adam Khoury @ www.flashbuilding.com
-----------------------June 20, 2008-----------------------
/
// Set error message as blank upon arrival to page
$errorMsg = “”;
// First we check to see if the form has been submitted
if (isset($_POST[‘username’])){
//Connect to the database through our include
include_once “/mypersonalsql.php”;
// Filter the posted variables
$username = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘username’]); // filter everything but numbers and letters
$country = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘country’]); // filter everything but spaces, numbers, and letters
$state = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘state’]); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘city’]); // filter everything but spaces, numbers, and letters
$accounttype = ereg_replace("[^a-z]", “”, $_POST[‘accounttype’]); // filter everything but lowercase letters
$email = stripslashes($_POST[‘email’]);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘password’]); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the “Required”(
) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$username) || (!$country) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password)){

	$errorMsg = "You did not submit the following required information!<br /><br />";
	if(!$username){
		$errorMsg .= "--- User Name";
	} else if(!$country){
		$errorMsg .= "--- Country"; 
	} else if(!$state){ 
	    $errorMsg .= "--- State"; 
   } else if(!$city){ 
       $errorMsg .= "--- City"; 
   } else if(!$accounttype){ 
       $errorMsg .= "--- Account Type"; 
   } else if(!$email){ 
       $errorMsg .= "--- Email Address"; 
   } else if(!$password){ 
       $errorMsg .= "--- Password"; 
   }
} else {
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
$sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check);
$email_check = mysql_num_rows($sql_email_check); 
if ($username_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else if ($email_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
} else {
	// Add MD5 Hash to the password variable
   $hashedPass = md5($password); 
	// Add user info into the database table, claim your fields then values 
	$sql = mysql_query("INSERT INTO members (username, country, state, city, accounttype, email, password, signupdate) 
	VALUES('$username','$country','$state','$city','$accounttype','$email','$hashedPass', now())") or die (mysql_error());
	// Get the inserted ID here to use in the activation email
	$id = mysql_insert_id();
	// Create directory(folder) to hold each user files(pics, MP3s, etc.) 
	mkdir("memberFiles/$id", 0755); 
	// Start assembly of Email Member the activation link
	$to = "$email";
	// Change this to your site admin email
	$from = "[email protected]";
	$subject = "Complete your registration";
	//Begin HTML Email Message where you need to change the activation URL inside
	$message = '<html>
	<body bgcolor="#FFFFFF">
	Hi ' . $username . ',
	<br /><br />
	You must complete this step to activate your account with us.
	<br /><br />
	Please click here to activate now &gt;&gt;
	<a href="http://www.somewebsite.com/activation.php?id=' . $id . '">
	ACTIVATE NOW</a>
	<br /><br />
	Your Login Data is as follows: 
	<br /><br />
	E-mail Address: ' . $email . ' <br />
	Password: ' . $password . ' 
	<br /><br /> 
	Thanks! 
	</body>
	</html>';
	// end of message
	$headers = "From: $from\r\n";
	$headers .= "Content-type: text/html\r\n";
	$to = "$to";
	// Finally send the activation email to the member
	mail($to, $subject, $message, $headers);
	// Then print a message to the browser for the joiner 
	print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />
	We just sent an Activation link to: $email<br /><br />
	<strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
	Link inside the message. After email activation you can log in.";
	exit(); // Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks

} // Close else after missing vars check
} //Close if $_POST
?>

Member Registration
REGISTER AS A MEMBER HERE
<?php echo $errorMsg; ?>
User Name:
Country:
<?php echo $country; ?> Australia Canada Mexico United Kingdom United States Zimbabwe
State:
City:
Account Type:
<?php echo $accounttype; ?> Normal User Expert User Super User
Email:
Password:
(letters or numbers only, no spaces no symbols)
Captcha:
Add Captcha Here for security
[/php]

Well, you did “fairly” well correcting the quotes inside of quotes…

But, you missed one important one…

In your section that creates the “$message”, you use single-quotes to delimit the “OUTSIDE” quotes.
You start your message info with "$message=’ some stuff ’ and then move into an “ANCHOR” for a
link. This is basically:

As you will note, it includes single-quotes! Sorry, that will not work. The first single-quote in the id=’ will
break your “OUTSIDE” quotes. The next single-quote restarts the “OUTSIDE” quotes. Therefore, in the
middle of these, you have some text which can go anywhere…
So, to fix that, you have two choices. First, you can break up the definition to make sure you use the
“OUTSIDE” quotes. Something like:
$message = “some stuff”;
$message .= “some more stuff”;
$message .= "<a HREF=“http…?id=’$id’>”;
$message .= “some more stuff”;
(Note: the .= means to add stuff to the previous value…)
OR, you can use “ESCAPE” characters…
would become something like:
This is usually easier.
I use both options depending on which reads better…

Hope that helps… Fix that one and let us know…

Thanks again! Let me edit it again now and I will post back here in a few minutes :slight_smile:

Hmm…am I not understanding something or miss something? I adjust what you said using the “ESCAPE” characters - Here is the code:

[php]<?php

$errorMsg = “”;
// First we check to see if the form has been submitted
if (isset($_POST[‘username’])){
//Connect to the database through our include
include_once “/mypersonalsql.php”;
// Filter the posted variables
$username = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘username’]); // filter everything but numbers and letters
$country = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘country’]); // filter everything but spaces, numbers, and letters
$state = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘state’]); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘city’]); // filter everything but spaces, numbers, and letters
$accounttype = ereg_replace("[^a-z]", “”, $_POST[‘accounttype’]); // filter everything but lowercase letters
$email = stripslashes($_POST[‘email’]);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘password’]); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the “Required”(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$username) || (!$country) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password)){

	$errorMsg = "You did not submit the following required information!<br /><br />";
	if(!$username){
		$errorMsg .= "--- User Name";
	} else if(!$country){
		$errorMsg .= "--- Country"; 
	} else if(!$state){ 
	    $errorMsg .= "--- State"; 
   } else if(!$city){ 
       $errorMsg .= "--- City"; 
   } else if(!$accounttype){ 
       $errorMsg .= "--- Account Type"; 
   } else if(!$email){ 
       $errorMsg .= "--- Email Address"; 
   } else if(!$password){ 
       $errorMsg .= "--- Password"; 
   }
} else {
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
$sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check);
$email_check = mysql_num_rows($sql_email_check); 
if ($username_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else if ($email_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
} else {
	// Add MD5 Hash to the password variable
   $hashedPass = md5($password); 
	// Add user info into the database table, claim your fields then values 
	$sql = mysql_query("INSERT INTO members (username, country, state, city, accounttype, email, password, signupdate) 
	VALUES('$username','$country','$state','$city','$accounttype','$email','$hashedPass', now())") or die (mysql_error());
	// Get the inserted ID here to use in the activation email
	$id = mysql_insert_id();
	// Create directory(folder) to hold each user files(pics, MP3s, etc.) 
	mkdir("memberFiles/$id", 0755); 
	// Start assembly of Email Member the activation link
	$to = "$email";
	// Change this to your site admin email
	$from = "[email protected]";
	$subject = "Complete your registration";
	//Begin HTML Email Message where you need to change the activation URL inside
	$message = '<html>
	<body bgcolor="#FFFFFF">
	Hi \' . $username . \',
	<br /><br />
	You must complete this step to activate your account with us.
	<br /><br />
	Please click here to activate now &gt;&gt;
	<a href="http://www.somewebsite.com/activation.php?id=\' . $id . \'">
	ACTIVATE NOW</a>
	<br /><br />
	Your Login Data is as follows: 
	<br /><br />
	E-mail Address: \' . $email . \' <br />
	Password: \' . $password . \' 
	<br /><br /> 
	Thanks! 
	</body>
	</html>';
	// end of message
	$headers = "From: $from\r\n";
	$headers .= "Content-type: text/html\r\n";
	$to = "$to";
	// Finally send the activation email to the member
	mail($to, $subject, $message, $headers);
	// Then print a message to the browser for the joiner 
	print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />
	We just sent an Activation link to: $email<br /><br />
	<strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
	Link inside the message. After email activation you can log in.";
	exit(); // Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks

} // Close else after missing vars check
} //Close if $_POST
?>

Member Registration
REGISTER AS A MEMBER HERE
<?php echo $errorMsg; ?>
User Name:
Country:
<?php echo $country; ?> Australia Canada Mexico United Kingdom United States Zimbabwe
State:
City:
Account Type:
<?php echo $accounttype; ?> Normal User Expert User Super User
Email:
Password:
(letters or numbers only, no spaces no symbols)
Captcha:
Add Captcha Here for security
[/php]

Sorry & Thank You again.

Is the php code on that page listed in the action or is it on the same page? if its on the same page, then you can remove the action.

You still missed one - $to = “$email”; > should be $to = $email;
The message is still off
[php]$message = "

Hi $username


You must complete this step to activate your account with us.



Please click here to activate now >>
ACTIVATE NOW



Your Login Data is as follows:



E-mail Address: $email

Password: $password



Thanks!

";[/php]
$to = “$to”; is redundant, have the same variable in there twice, the bottom one needs to be deleted

Using exit() to keep the page short is just wrong and can screwup a layout horribly. You’re much better off putting the activation notification in a variable and using if(isset()) to dispaly it when needed. That way, your page stays in tact and you can put the message anywhere you need it.

Also, you may want to look into switching to preg_match() instead of using ereg, as ereg has been depreciated in recent versions of php - will give you error messages when its live.

Richei: Okay, I removed the quotes from the one email you mentioned. Honestly, I am not that great with MySQL as I just started so I am having a tough time understanding what you said :frowning: I am online now and going to keep rereading to understand :slight_smile:

PS: The code you placed up in your prior message, is that what it SHOULD be?

PS question: Yes, that’s what its supposed to be.

Well, it looks like you copied that from a tutorial or something, which isn’t a bad thing, but hard to troubleshoot if you’re don’t know what you’re doing.

So first things first, make sure the data is getting there. Add this right under the first if statement
echo “

”;
print_r($_POST);
echo “
”;

what that will do is give you something like

Array("key" => "value" "key" => "value" "key" => "value" "key" => "value" )
For each input name, you should have a key and a value. If one is missing or there’s no value, then you what to check for spelling. If everything is there, then we need to add some echos to the email validation to see where its going wrong.

Okay, wonderful :slight_smile: This is slowly starting to make sense to me.

I did update the message coding as you placed it.

You said to put the other information under the first statement, so like this…?

[php]<?php

$errorMsg = “”;
// First we check to see if the form has been submitted
if (isset($_POST[‘username’])){
echo “

”;
print_r($_POST);
echo “
”;
//Connect to the database through our include
include_once “/mypersonalsql.php”;
// Filter the posted variables
$username = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘username’]); // filter everything but numbers and letters
$country = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘country’]); // filter everything but spaces, numbers, and letters
$state = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘state’]); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Z a-z0-9]", “”, $_POST[‘city’]); // filter everything but spaces, numbers, and letters
$accounttype = ereg_replace("[^a-z]", “”, $_POST[‘accounttype’]); // filter everything but lowercase letters
$email = stripslashes($_POST[‘email’]);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", “”, $_POST[‘password’]); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the “Required”(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$username) || (!$country) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password)){
	$errorMsg = "You did not submit the following required information!<br /><br />";
	if(!$username){
		$errorMsg .= "--- User Name";
	} else if(!$country){
		$errorMsg .= "--- Country"; 
	} else if(!$state){ 
	    $errorMsg .= "--- State"; 
   } else if(!$city){ 
       $errorMsg .= "--- City"; 
   } else if(!$accounttype){ 
       $errorMsg .= "--- Account Type"; 
   } else if(!$email){ 
       $errorMsg .= "--- Email Address"; 
   } else if(!$password){ 
       $errorMsg .= "--- Password"; 
   }
} else {
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
$sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check);
$email_check = mysql_num_rows($sql_email_check); 
if ($username_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else if ($email_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
} else {
	// Add MD5 Hash to the password variable
   $hashedPass = md5($password); 
	// Add user info into the database table, claim your fields then values 
	$sql = mysql_query("INSERT INTO members (username, country, state, city, accounttype, email, password, signupdate) 
	VALUES('$username','$country','$state','$city','$accounttype','$email','$hashedPass', now())") or die (mysql_error());
	// Get the inserted ID here to use in the activation email
	$id = mysql_insert_id();
	// Create directory(folder) to hold each user files(pics, MP3s, etc.) 
	mkdir("memberFiles/$id", 0755); 
	// Start assembly of Email Member the activation link
	$to = $email;
	// Change this to your site admin email
	$from = "[email protected]";
	$subject = "Complete your registration";
	//Begin HTML Email Message where you need to change the activation URL inside
	$message = "<html>
<body bgcolor='#FFFFFF'>
Hi  $username <br /><br />
You must complete this step to activate your account with us.
<br /><br />
Please click here to activate now &gt;&gt;
<a href='http://www.somewebsite.com/activation.php?id=$id'>ACTIVATE NOW</a>
<br /><br />
Your Login Data is as follows:
<br /><br />
E-mail Address: $email<br />
Password: $password
<br /><br />
Thanks!
</body>
</html>";
	// end of message

[/php]

I cut off the bottom portion of the code.

Now when I try to register, I still get the error and:

Array
(
[username] => infohere
[country] => United States
[state] => Nevada
[city] => Las Vegas
[accounttype] => c
[email] => infohere
[password] => infohere
[Submit] => Submit Form
)

ok, so all the data seems to be there, no spelling errors. What is the error that your getting? still a problem with the email?

You did not submit the following required information!

— Email Address

That is my error - I fill everything out and then when I click submit, the email address I put in disappears and it gives me the error as if I never put it in.

I do not know why it would, but do you think it may be due to an error on my activation page? I do not know why it would but I am just throwing it out there :slight_smile:

Thank you again for trying to help! I REALLY appreciate it. I am just trying to get this up and running.

ok, 1 thing to try. instead of using $_POST[‘username’] in the first if statement, try using $_POST[‘submit’] (or whatever the name is of your submit button). Because if the name is empty, its not going to process the code.

AHH! :stuck_out_tongue: No error popped up!

However…when I clicked submit, it acted as if it re loaded but the page stayed the same with all my information still there…

Because you’re telling it to. Look at the value of your inputs.

Sponsor our Newsletter | Privacy Policy | Terms of Service