Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Earth
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code to say that the email is in use, or code to say that certain fields are missing

    just as the title says.

    ok, in the script i have, i didn't get the 'your email address is already in use' so how do i write that.

    there are two parts, one for userid in use, and one for passwords don't match

    see, like so


    PHP Code:
    if($signuppassword!=$signuppasswordverify) { 
     
    create_error_page_passwordsnotmatch(); 
    or
    PHP Code:
    if ($num_rows == 1) { 
     
    create_error_page_useridinuse(); 
    what do i do now? to make it look for a unuque email

    i want to learn how to edit a script myself.
    Life is funny, especially when you're poor.

  • #2
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php

    // searches the table for that email and selects it if it finds it
    $getQuery "SELECT * FROM table WHERE email='$email'";

    $result mysql_query($getQuery);

    // mysql_numrows() gets the number of rows selected
    // if it finds the email address it will return 1 (used)
    $checkE mysql_numrows($result);

    // return an error
    if($checkE >= "1")
    {
        echo 
    "Invalid E-mail address, "$email ." is already used";
        
        
    // halt and exit script so nothing else will be exicuted
        
    exit;
    }


    ?>

  • #3
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    for checking for blank fields..


    PHP Code:
    <?php

    if($formField1 == "")
    {
        echo 
    "you left formField 1 blank";
        exit;
    }
    if(
    $formField2 == "")
    {
        echo 
    "you left formField 2 blank";
        exit;
    }
    if(
    $formField3 == "")
    {
        echo 
    "you left formField 3 blank";
        exit;
    }

    ?>
    i would recommend using javascript for this though. it is much faster and also keeps the user from having to go back and filling out the form over agian. which would be a real pain on a big form.


    <script language="javascript">
    function check()
    {

    if(document.FORMNAME.FIELDNAME.value == "")
    {
    // alert the user of blank field
    alert("FIELDNAME was left blank!";

    // return false to stop submition
    return false;
    }

    }
    </script>

    use the onsubmit to check:

    <form method="" action="" onsubmit="return check()">

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Earth
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tried adding the email code into the script, it didn't work.


    should i post the script for you to show me where to put that string, or should i just include it at teh top as if it's a seperate script?
    Life is funny, especially when you're poor.

  • #5
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah go ahead and post the whole thing

    go here for an example of the javascript. just press post

    http://phip.chronicyouth.com/chronic...p?do=sign-book

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    Earth
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <? 
    // User Sign Up PHP Script 
    // 
    // This script validates information, saves it to the database 
    // displays it to them 
    // and sends it to them via email 
    // 
    // vars: 
    // $signupusername 
    // $signuppassword 
    // $signuppasswordverify 
    // $signupemailaddress 
    // 
    // Note have to use signup* vars initially to make it clear to ourselves that 
    // we're dealing with signupotherwise 

    // Include common variables and message text 
    include 'zcommon.php'

    //null out cookies if new user 
    //null out cookies at start of sign in routine 
    //all cookies begin with "ck_" to indicate that they are a cookie 
    //helps troubleshoot mysterious cookie errors 
    // note on using cookies. 
    // MUST BE SET before ANY http output. 
    // They TRAVEL in the http HEADER so have to go first. 
    setcookie ("ck_user"""); 
    setcookie ("ck_password"""); 
    setcookie ("ck_user_id"""); 

    // 0th check that passwords match 
    if($signuppassword!=$signuppasswordverify) { 
     
    create_error_page_passwordsnotmatch(); 

    else { 
    // their passwords match so enter next validation stage 
    // first test that their username isn't already in use 

    // Connecting, selecting database 
    $link mysql_connect("$dbhost""$dbuser""$dbpassword"
     or die(
    "Could not connect"); 
    //select the database 
    mysql_select_db("$db"
     or die(
    "Could not select database"); 
    //try and select the username that the user entered to see if it is already in the db 
    $query "SELECT userid " 
    " FROM users " 
    " WHERE userid='$signupusername'"

    $result mysql_query($query
     or die(
    "Query failed at username unique testing stage."); 

    //logic -- if the num_rows is 1 then the username is already in use 
    // and they have to choose another 
    $num_rows mysql_num_rows($result); 
    //don't need to get it -- its the same as what we already have 

    //num_rows can't ever be >= to 1 since unique constraint on the column of data 
    if ($num_rows == 1) { 
     
    create_error_page_useridinuse(); 

    else { 
     
    // NOTE -- Depending on how you want to define 
     // a valid password (5 chars, 6 chars 
     // plus a number, etc), that would go here 

     //Capture the ipaddress and call MD5 
       
    $ipaddress getenv ("REMOTE_ADDR"); 
       
    $encryptedpassword md5($signuppassword); 

     
    //try and add them to the database 
     
    $query "INSERT INTO users " 
       
    " ( userid, password, date, ipaddress, email, fullname, hintquestion, hintanswer ) " 
       
    " VALUES ('$signupusername','$encryptedpassword', 
              NOW(), '$ipaddress', '$emailaddress', '$signupname', '$signuphint', '$signupanswer')"


     
    //execute the query 
     
    $result mysql_query($query
       or die(
    "Query failed at user insertion stage."); 

     
    //now query the db back for the user_id variable 
     
    $query "SELECT user_id " 
       
    " FROM users " 
       
    " WHERE userid='$signupusername'"

     
    // get the result 
     
    $result mysql_query($query
       or die(
    "Query failed at userid retrieval stage."); 

     
    //get the user_id from the result 
     
    $num_rows mysql_num_rows($result); 
       
    $row mysql_fetch_array($result); 
       
    $user_id $row[0]; 

     
    // send the cookies now. MUST BE FIRST THING OUTPUT 
     
    setcookie ("ck_userid""$signupusername"); 
     
    setcookie ("ck_password""$signuppassword"); 
     
    setcookie ("ck_user_id""$user_id"); 

     
    //Define the $title variable for the page title 
     
    $title "Thanks for Signing Up!"

     
    //Set up the page header 
     
    PrintPageHeader("$title"); 

     
    //Print out the body of the page 
     // Note that some basic html formatting is used 
     // here to make it look better 
     
     
    print "<TABLE WIDTH=728 BGCOLOR=WHITE><TR><TD>"
     print 
    "<H1>Thank You...</H1>"
     print 
    "<HR>"
     print 
    "<CENTER>Welcome $signupname! "
     print 
    "Hope you enjoy the "
     print 
    "site.</CENTER><BR><BR>"
     print 
    "Here is the information that you entered:"
     print 
    "<UL>"
     print 
    "<LI>Username: $signupusername</LI>"
     print 
    "<LI>Password: $signuppassword</LI>"
     print 
    "<LI>Email Address: $emailaddress</LI>"
     print 
    "</UL>"
     print 
    "<BR>We have also emailed this to the email "
     print 
    "address you gave us.<BR>"
     print 
    "</TD>"
     print 
    "</TR>"
     print 
    "<TABLE>"

     
    //Usually you want to add a link to your 
     // application's home page here. 
     // Left as an exercise for the reader. 

     //handle sending out the email if we got an email address! 
     
    if ($emailaddress != "") { 
       
    // compose the email 
       
    $to $emailaddress
       
    $subject "Your Membership"
       
    $message "Welcome $signupname, " 
       
    "
       
       Your account has been created and is ready for use." 
       
    "" 
       
       
    "" 
       

       
       Your username is: $signupusername" 
       
    "   
       Your password is: $signuppassword" 
       
    "" 
       
    "
       
       Thanks for signing up to A." 
       
    "
       
       [url]http://www.me.com/[/url]" 
       
    "" 
       
    "
       
       Jewle,
       Webmaster
       [email]webmaster@me.com[/email]"

       
    // send the email 
       
    mail($to$subject$message"From: [email]webmaster@me.com[/email]""- 
          [email]fwebmaster@me.com[/email]"
    ); 
      } 

    //Set up the footer of the page 
     
    PrintPageFooter(""); 
     } 


    // start of functions 

    function PrintPageHeader ($title) { 
     print 
    "<HTML>"
     print 
    "<HEAD>"
     print 
    "<TITLE>"
     print 
    "$title"
     print 
    "</TITLE>"
     print 
    "</HEAD>"
     print 
    "<BODY>"


    function 
    PrintPageFooter ($title) { 
     print 
    "</BODY>"
     print 
    "</HTML>"



    function 
    create_error_page_passwordsnotmatch() { 
     
    //Define the $title variable for the page title 
     
    $title "We're Sorry But You're Passwords Don't Match!"

     
    //Set up the page header 
     
    PrintPageHeader("$title"); 

     print 
    "<TABLE WIDTH=728 BGCOLOR=WHITE><TR><TD>"
     print 
    "<H1>We're Sorry...</H1>"
     print 
    "<HR>"
     print 
    "<BR>"
     print 
    "We're sorry but You didn't enter matching passwords. "
     print 
    "&nbsp;Please make sure that you enter your password "
     print 
    "in the Password field and the Verify Password fields "
     print 
    "and that both are the same.<BR><BR>"
     print 
    "Please press the back button and make sure that the "
     print 
    "passwords match."

     
    // close container table 
     
    print "</TD></TR></TABLE>"

     
    //Set up the footer of the page 
     
    PrintPageFooter(""); 



    function 
    create_error_page_useridinuse() { 
     
    //Define the $title variable for the page title 
     
    $title "We're Sorry But that Username is Already in Use..."

     
    //Set up the page header 
     
    PrintPageHeader("$title"); 

     print 
    "<TABLE WIDTH=728 BGCOLOR=WHITE><TR><TD>"

     print 
    "<H1>We're Sorry...</H1>"
     print 
    "<HR>"
     print 
    "<BR>You entered a Username that another person is using"
     print 
    "<BR>Press Back to try again."
     
    // close container table 
     
    print "</TD></TR></TABLE>"

     
    //Set up the footer of the page 
     
    PrintPageFooter(""); 


    ?>

    hey, is there anyway i could get an email sent to me if someone signs up. I don't want any passwords or anything, just to have the user name, or even to have 'someone's signed up' or something
    Life is funny, especially when you're poor.

  • #7
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just at the mail() to the sign up

    i'm looking over your script..

  • #8
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what is it not doing? or what orrors do you get?

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    Earth
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Query failed at user insertion stage.


    that's what it's saying. Instead of saying it's the same email address.

    if i put a different email address in, then it works fine.
    Life is funny, especially when you're poor.

  • #10
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    quick lesson

    wont work
    $query = "SELECT user_id "

    . " FROM users "

    . " WHERE userid='$signupusername'";

    needs to be

    $query = "SELECT user_id " ;

    $query .= " FROM users ";

    $query .= " WHERE userid='$signupusername'";

    what you have will just flatten out and $query will pretty much be destroyed and not work.

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Location
    Earth
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    regardless of which, there must be a message to give the user, right?
    Life is funny, especially when you're poor.

  • #12
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    umm... say what? i don't understand how that relates to solving this.

  • #13
    Regular Coder
    Join Date
    Jul 2002
    Location
    Earth
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no no, the sign up script works fine. no worries.

    but what i'm trying to do is this


    A. tell the user when he is trying to sign up with an email address that's already listed.

    B. send myself an email when someone signs up

    C. (as you already told me how to do) just to make sure they fill out the proper fields.

    i wanted to know where in the code i should put that email script you gave me.
    Life is funny, especially when you're poor.

  • #14
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    right after else{ because the user has been validated and signed up

    if ($num_rows == 1) {

    create_error_page_useridinuse();

    }

    else {

  • #15
    Regular Coder
    Join Date
    Jul 2002
    Location
    Earth
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    didn't work. still the same error

    if i included your script by itself, would that work?
    Life is funny, especially when you're poor.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •