Jump to content

help: Alertbox with email dupliction checking.

- - - - -

  • Please log in to reply
7 replies to this topic

#1
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
Hi i have here summary of my code in php with alert-box, it is working, im just having a problem combining 2 conditions in like checking the email if its duplicated.

i also have the code and its working. i just don't know how to combine the 2.
i checks for the email but still sends the message to the email because the other condition is correct.

pls. help me. thanks.


<?php

$problem = FALSE; //no problem

    

    //check value

    $themessage = "You are required to complete the following fields: ";

    if (empty($fguess)){

    $problem = TRUE;

    $themessage.= 'First guess';

    }

    if (empty($sguess)){

    $problem = TRUE;

    $themessage.=',Second guess,';

    }

    if (empty($tguess)){

    $problem = TRUE;

    $themessage.=',Third guess';

    }

    if (empty($_POST['f_name'])){

    $problem = TRUE;

    $themessage.=',First Name';

    }

    if (empty($m_name)){

    $problem = TRUE;

    $themessage.=',Middle Name';

    }

    if (empty($l_name)){

    $problem = TRUE;

    $themessage.=',Last Name';

    }

    if (empty($h_address)){

    $problem = TRUE;

    $themessage.=',Home Address';

    }

    if (empty($email)){

    $problem = TRUE;

    $themessage.=',Email Address';

    }

    if (empty($contact)){

    $problem = TRUE;

    $themessage.=',Contact No';

    }

    if (empty($job)){

    $problem = TRUE;

    $themessage.=',Job Title';

    }


    //Print alert box with error message if there is a problem

    if($problem) {

    print("<script>alert('$themessage')</script>");

    }

?> 


here is the email checking


	$emailchk = mysql_query("SELECT * FROM shinygame WHERE email = '$email'");   

	if(mysql_num_rows($emailchk) > 0) { 

	$error = 1;

	}

	if ($error) 

	{   print("<script>alert('Email is already registered, pls. try again.')</script>");

		print "<script type=\"text/javascript\">";

		print "window.location.href = 'game.php'";

		print "</script>"; 

		

	}


how do i combine the two codes to make it one.

Thank you!

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You would need to check if the email is in the database (up top) and then in the checking area, if it does exist in the database make the $themessage variable the error you wish for.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
yes i have it placed at the top, but still i will say your email is duplicate but the second condition is true thats why it still sends the form to the email. im doing 2 submit with it.
i dont know how to combine the 2.

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You should put it as another if statement instead of doing two separate error checkings.
    if (mysql_num_rows($emailchk) > 0){ 
    $problem = TRUE; 
    $themessage.=', Email already exists in our database'; 
    } 

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
rhossis

rhossis

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Hi, just to clarify, do you mean comparing emails in two textboxes whereby user has to input the email twice e.g. in in a user registration?

#6
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
Hi,

no, i want to check if the email already exist in my database. if it exits the user need to input another email.

Thanks for your help.

#7
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Have you tried adding it to the IF statements as you have all the other errors? I would recommend you visualize what you need to put where, and test some code and we can see if it looks good!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#8
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts

Alexander said:

Have you tried adding it to the IF statements as you have all the other errors? I would recommend you visualize what you need to put where, and test some code and we can see if it looks good!

Hi alexander,

i have solved this problem. thank you for your help. at first i was having problem with the code you posted, i just forgot to un-comment one line.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users