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.
Results 1 to 6 of 6
  1. #1
    Banned
    Join Date
    May 2008
    Posts
    105
    Thanks
    9
    Thanked 0 Times in 0 Posts

    need an answer really quick

    Hello.

    I have got a registration form and i only have the Username and Password bit.
    So i want to add an email bit as well.

    So here is the php code:

    PHP Code:
    <?
    session_start
    (); 
    include(
    "database.php");

    /**
     * Returns true if the username has been taken
     * by another user, false otherwise.
     */
    function usernameTaken($username){
       global 
    $conn;
       if(!
    get_magic_quotes_gpc()){
          
    $username addslashes($username);
       }
       
    $q "select username from users where username = '$username'";
       
    $result mysql_query($q,$conn);
       return (
    mysql_numrows($result) > 0);
    }

    /**
     * Inserts the given (username, password) pair
     * into the database. Returns true on success,
     * false otherwise.
     */
    function addNewUser($username$password){
       global 
    $conn;
       
    $q "INSERT INTO users VALUES ('$username', '$password')";
       return 
    mysql_query($q,$conn);
    }

    /**
     * Displays the appropriate message to the user
     * after the registration attempt. It displays a 
     * success or failure status depending on a
     * session variable set during registration.
     */
    function displayStatus(){
       
    $uname $_SESSION['reguname'];
       if(
    $_SESSION['regresult']){
    ?>

    <h1>Registered!</h1>
    <p>Thank you <b><? echo $uname?></b>, your player information has been recorded, you may now <a href="index.php" title="Login">log in</a>.</p>

    <?
       
    }
       else{
    ?>

    <h1>Registration Failed</h1>
    <p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname?></b>, could not be completed.<br>
    Please try again at a later time.</p>

    <?
       
    }
       unset(
    $_SESSION['reguname']);
       unset(
    $_SESSION['registered']);
       unset(
    $_SESSION['regresult']);
    }

    if(isset(
    $_SESSION['registered'])){
    /**
     * This is the page that will be displayed after the
     * registration has been attempted.
     */
    ?>

    <html>
    <title>Registration Page</title>
    <body>

    <? displayStatus(); ?>

    </body>
    </html>

    <?
       
    return;
    }

    /**
     * Determines whether or not to show to sign-up form
     * based on whether the form has been submitted, if it
     * has, check the database for consistency and create
     * the new account.
     */
    if(isset($_POST['subjoin'])){
       
    /* Make sure all fields were entered */
       
    if(!$_POST['user'] || !$_POST['pass']){
          die(
    'You didn\'t fill in a required field.');
       }

       
    /* Spruce up username, check length */
       
    $_POST['user'] = trim($_POST['user']);
       if(
    strlen($_POST['user']) > 30){
          die(
    "Sorry, the username is longer than 30 characters, please shorten it.");
       }

       
    /* Check if username is already in use */
       
    if(usernameTaken($_POST['user'])){
          
    $use $_POST['user'];
          die(
    "Sorry, the username: <strong>$use</strong> is already taken, please pick another one.");
       }

       
    /* Add the new account to the database */
       
    $md5pass md5($_POST['pass']);
       
    $_SESSION['reguname'] = $_POST['user'];
       
    $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass);
       
    $_SESSION['registered'] = true;
       echo 
    "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
       return;
    }
    else{
    /**
     * This is the page with the sign-up form, the names
     * of the input fields are important and should not
     * be changed.
     */
    ?>

    <html>
    <title>Registration Page</title>
    <body>
    <h1>Register</h1>
    <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
    <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
    <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr>
    </table>
    </form>
    </body>
    </html>


    <?
    }
    ?>
    So could anyone help?

    Thanks in advance
    9homie

  • #2
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Just before...
    PHP Code:
    echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">"
    put something similar to...
    PHP Code:
    mail($_POST['email'], 'MySite.com Registration Info'"Thanks for registering! Sign in at any time using your information listed below:\r\n\r\nUsername: $_POST[user]\r\nPassword: $_POST[password]""Content-type: text/plain\r\n"); 
    Of course you'll have to include an email field in your form and check that for empty/valid as well.
    Last edited by syosoft; 05-19-2008 at 02:49 AM. Reason: Typos
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

  • #3
    Banned
    Join Date
    May 2008
    Posts
    105
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I don't really get what you mean. On all the others you have to put a load of coding and you are saying that i have to have like less that 1 line for the email.
    So do you know how to add it to the database and so on for that?

  • #4
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    On other posts I have written far more code. If you don't try offered solutions, how can anyone help? If you don't think what I offered up will work, try it and prove me wrong and feel free to clarify. I'll attempt to offer more assistance.

    "An e-mail bit" is classic client talk for "I dont know what I need, but i want it cheap and to work far better than I can imagine." I simply made an assumption about what you were after. Emailing registration data.
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    What you want to do is really not that hard once you start to grasp php better. Its taken me about a year to start getting comfortable with it.

    What you want to do will require a 3 or 4 step process. I won't give you the full blown how to, but more of a guide. This way, hopefully you'll start to grasp some of the concepts. Just start to look at how the username is added to the database. Follow the username and its variables through the code, and it will start to make more sense.

    Step 1. You need to add the email data to your form.
    Step 2. Pass that data to your function using $_POST
    Step 3. Add the $email variable to the the function

    PHP Code:
     $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass$email); 
    Step 4. Add the the email to the query

    PHP Code:
    $q "INSERT INTO users VALUES ('$username', '$password', '$email')"
    Now, there's more to do here, such as sanitizing your data, ensure you do actually have an email field in your users table, etc. But the above is mainly what you need to do.

    FYI. I'm using that same login code that I've modified myself. You should be able to figure it out with a little effort.

  • #6
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    ohhh - he wanted an email form field? Heh, I suggested that he create that field to get the desired "email" functionality.

    Poorly worded question.
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready


  •  

    Posting Permissions

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