Jump to content

Recommended Posts

Hey All,

 

i have been working on a website to try and get me used to PhP. By using several books i have got the hang of most parts but i cant for the life of me understand why i keep getting the same problems.

 

First name and Last names always show as an error even if you enter something in the field.

 

when i enter all fields i get an escape_data() error. I just cant get it past these two significant parts.

 

Thanks for any help because im getting very far at the moment

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/183912-registration-page-problems/
Share on other sites

Next time, please post the relevant code inside of


tags.

 

I do not know where the function escape_data is located at, as it is not in that script you gave us, perhaps you meant mysql_real_escape_string. Try replacing the escape_data to the mysql function and see if that works.

Ah sorry will do from now on.

 

Well i have changed the error tags and now it just gets my last variable echo of "Please try again" everytime i enter any data.

 

Thanks for any help

 


<?php 

if (eregi ('^[[:alpha:]\.\'\-]{2,15}$', stripslashes(trim($_POST['first_name'])))) {
						$fn = mysql_real_escape_string($_POST['first_name']);
}
else
{
	$fn = FALSE;
	echo '<p><font color ="red" size="+1"> Please enter your first name!</font></p>';
}

if (eregi ('^[[:alpha:]\.\'\-]{2,30}$', stripslashes(trim($_POST['last_name'])))) {
						$fn = mysql_real_escape_string($_POST['last_name']);
}
else
{
	$ln = FALSE;
	echo '<p><font color ="red" size="+1"> Please enter your last name!</font></p>';
}
    
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
	$e = mysql_real_escape_string($_POST['email']);
}
else
{
	$e = FALSE;
	echo '<p><font color ="red" size="+1"> Please enter a correct e-mail address</font></p>';
}

if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST['password1'])))) {

if ($_POST['password1'] == $_POST['password2']) {

$p = mysql_real_escape_string($_POST['password1']);
}
else
{
	$p = FALSE;
	echo '<p><font color ="red" size="+1"> Your password did not match the confirmed password!</font></p>';
}
}
else
{
	$p = FALSE;
	echo '<p><font color ="red" size="+1"> Please enter a valid password!</font></p>';
}

if ($fn && $ln && $e && $p) {
	$query ="SELECT username FROM users WHERE email='$e'";
	$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error());

	if (mysql_num_rows($result) == 0) {

		$a = md5(uniqid(rand(), true));

		$query = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', '$p', $'f',	 $'ln', $'a' )";
    $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error());

if (mysql_affected_rows() == 1) {

	$body = "Thank you for registering with Football Trip. Please use the link below to activate your account:\n\n";
	$body .= "http://www.footballtrip.net/activate.php?x=" . mysql_insert_id() . "&y=$a";
	mail($_POST['email'],'Registration Comfirmation',$body);
	echo '<h2> Thank you for registering! A confirmation E-Mail has been sent to your address. Please click on the link in
				order to activate your account</h2>';

}
else
{

	echo '<p>font color="red" size="+1"> You could not be registered due to a system error. We apologize for any inconvenience. 			                 </font></p>';
}
	} else {
		echo '<p><font color="red" size="+1"> That E-Mail address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>';
	}
	} else { 
		echo '<p><font color="red" size="+1"> Please try again.</font></p>';
	}

	mysql_close();


	?>   

Ok I cleaned up the indentation so it was easier to read and removed the multiple checks, since you were not using them to display a certain error and just made a $error to test if there was an error prior:

 

<?php 
$error = false;
if (eregi ('^[[:alpha:]\.\'\-]{2,15}$', stripslashes(trim($_POST['first_name'])))) {
$fn = mysql_real_escape_string($_POST['first_name']);
}else {
$error = true;
echo '<p><font color ="red" size="+1"> Please enter your first name!</font></p>';
}
   
if (eregi ('^[[:alpha:]\.\'\-]{2,30}$', stripslashes(trim($_POST['last_name'])))) {
$fn = mysql_real_escape_string($_POST['last_name']);
}else {
$error = true;
echo '<p><font color ="red" size="+1"> Please enter your last name!</font></p>';
}
    
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
$e = mysql_real_escape_string($_POST['email']);
}else {
$error = true;
echo '<p><font color ="red" size="+1"> Please enter a correct e-mail address</font></p>';
}
   
if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST['password1'])))) {
if ($_POST['password1'] == $_POST['password2']) {
	$p = mysql_real_escape_string($_POST['password1']);
}else {
	$error = true;
	echo '<p><font color ="red" size="+1"> Your password did not match the confirmed password!</font></p>';
}
}else {
$error = true;
echo '<p><font color ="red" size="+1"> Please enter a valid password!</font></p>';
}
   
if (!$error) {
$query ="SELECT username FROM users WHERE email='$e'";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error());
      
if (mysql_num_rows($result) == 0) {
	$a = md5(uniqid(rand(), true));
	$query = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', '$p', $'f',    $'ln', $'a' )";
	$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error());
   
	if (mysql_affected_rows() == 1) {
		$body = "Thank you for registering with Football Trip. Please use the link below to activate your account:\n\n";
		$body .= "http://www.footballtrip.net/activate.php?x=" . mysql_insert_id() . "&y=$a";
		mail($_POST['email'],'Registration Comfirmation',$body);
		echo '<h2> Thank you for registering! A confirmation E-Mail has been sent to your address. Please click on the link in
		order to activate your account</h2>';
	}else {
		echo '<p>font color="red" size="+1"> You could not be registered due to a system error. We apologize for any inconvenience.                           </font></p>';
	}
}else {
	echo '<p><font color="red" size="+1"> That E-Mail address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>';
}
} else { 
echo '<p><font color="red" size="+1"> Please try again.</font></p>';
}
      
mysql_close();

?>  

 

Give that a try and see if it works.

brilliant thanks, i changed a few things as it reported some errors but it sends the values to mysql.

 

one problem is that it seems to put last name in the first name section of the mysql database. I cant understand why though any ideas?

 


        <form action="register.php" method="post">
        	<fieldset>
            
            <p><b> First Name:</b> <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
            
            <p><b> Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
            
            <p><b> E-Mail Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
            
            <p><b> Password:</b> <input type="password" name="password1" size="20" maxlength="20" /></p>
            <small> Use only letters and numbers. Must be between 4 and 20 Characters long. </small>
            
            <p><b> Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>
            
            </fieldset>
            
            <input type="submit" name="submit" value="Register" />
            <input type="hidden" name="submitted" value="TRUE" />
            
            </form>
            
            
<?php 
$error = false;
if (eregi ('^[[:alpha:]\.\'\-]{2,15}$', stripslashes(trim($_POST['first_name'])))) {
   $fn = mysql_real_escape_string($_POST['first_name']);
}else {
   $error = true;
   echo '<p><font color ="red" size="+1"> Please enter your first name!</font></p>';
}
   
if (eregi ('^[[:alpha:]\.\'\-]{2,30}$', stripslashes(trim($_POST['last_name'])))) {
   $fn = mysql_real_escape_string($_POST['last_name']);
}else {
   $error = true;
   echo '<p><font color ="red" size="+1"> Please enter your last name!</font></p>';
}
    
if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
   $e = mysql_real_escape_string($_POST['email']);
}else {
   $error = true;
   echo '<p><font color ="red" size="+1"> Please enter a correct e-mail address</font></p>';
}
   
if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST['password1'])))) {
   if ($_POST['password1'] == $_POST['password2']) {
      $p = mysql_real_escape_string($_POST['password1']);
   }else {
      $error = true;
      echo '<p><font color ="red" size="+1"> Your password did not match the confirmed password!</font></p>';
   }
}else {
   $error = true;
   echo '<p><font color ="red" size="+1"> Please enter a valid password!</font></p>';
}
   
if (!$error) {
   $query ="SELECT username FROM users WHERE email='$e'";
   $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error());
      
   if (mysql_num_rows($result) == 0) {
      $a = md5(uniqid(rand(), true));
      $query = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', '$p', '$fn', '$ln', '$a', NOW() )";
      $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error());
   
      if (mysql_affected_rows() == 1) {
         $body = "Thank you for registering with Football Trip. Please use the link below to activate your account:\n\n";
         $body .= "http://www.footballtrip.net/activate.php?x=" . mysql_insert_id() . "&y=$a";
         mail($_POST['email'],'Registration Comfirmation',$body);
         echo '<h2> Thank you for registering! A confirmation E-Mail has been sent to your address. Please click on the link in
         order to activate your account</h2>';
      }else {
         echo '<p><font color="red" size="+1"> You could not be registered due to a system error. We apologize for any inconvenience.                           </font></p>';
      }
   }else {
      echo '<p><font color="red" size="+1"> That E-Mail address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>';
   }
} else { 
   echo '<p><font color="red" size="+1"> Please try again.</font></p>';
}
      
mysql_close();

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.