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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    User Registration Help with coding

    hey guys I have the following code I got out of a book for a user registration form. What I am needing to know is how am I suppose to connect to my MYSQL database. Can you guys tell me how to do this?

    EDIT ***THE LINK TO THE PAGE IS http://www.52designs.net/php/register.php ****
    Here is the code I have:

    PHP Code:
    <?php
    function in_use($userName) {
        global 
    $member

        $query 
    "SELECT userName FROM $member WHERE userName = '$userName'";
        
    $result mysql_query($query) ;
        if(!
    mysql_num_rows($result)) return 0;
        else return 
    1;
    }

    function 
    register_form() {
        global 
    $userName$email$firstName$lastName;
    global 
    $PHP_SELF;
    ?>
    <center><h3>Create Your Account!</h3></center>
    <form method="POST" action="<?php echo $PHP_SELF ?>">
    <input type="hidden" name="action" value="register">
    <div align="center"><center><table border="1" width="90%">
    <tr>
    <th width="30%" nowrap>Desired User Name</th>
    <td width="70%"><input type="text" name="userName" value="<?php echo $userName ?>" size="8" maxlength="8"></td>
    </tr>

    <tr>
    <th width="30%" nowrap>Desired Password</th>
    <td width="70%"><input type="PASSWORD" name="password" value="<?php echo $password ?>" size="8" maxlength="8"></td>
    </tr>

    <tr>
    <th width="30%" nowrap>Retype Password</th>
    <td width="70%"><input type="PASSWORD" name="password2" size="15"></td>
    </tr>

    <tr>
    <th width="30%" nowrap>First Name</th>
    <td width="70%"><input type="text" name="FirstName" value="<?php echo $firstName ?>" size="20"></td>
    </tr>

    <tr>
    <th width="30%" nowrap>Last Name</th>
    <td width="70%"><input type="text" name="lastName" value="<?php echo $lastName ?>" size="20"></td>
    </tr>

    <tr>
    <th width="30%" nowrap>E-Mail Address</th>
    <td width="70%"><input type="text" name="emai;" value="<?php echo $email ?>" size="20"></td>
    </tr>

    <tr>
    <th width="30%" colspan="2" nowrap>
    <input type="submit" value="Submit">
    <input type="reset" value="Reset"></th></tr></table></center></div></form>

    <?php
    }
    function 
    create_account() {
    global 
    $userName$password$password2$firstName$lastName$email;
    global 
    $db234976774$member;
    if(empty(
    $userName)) error_message("Enter your Desired User Name!");
    if(empty(
    $password)) error_message("Enter your desired password!");
    if(
    strlen($password) < error_message("Password too short!");
    if(empty(
    $password2)) error_message("Retype your password for verification!");
    if(empty(
    $firstName)) error_message("Enter your First Name!");
    if(empty(
    $lastName)) error_message("Enter your Last Name!");
    if(empty(
    $email)) error_message("Enter your E-Mail!");
    if(
    $password != $password2error_message("Passwords Do not match, please verify them!");
    $link_id db_connect($db234976774);
    if(
    in_use($userName)) error_message("$userName is in use.  Please choose a different ID.");
    $query "INSERT INTO member VALUES ('$userName', password('$password'), '$username', '$email', '$firstName', '$lastName')";
    $result mysql_query($query);
    if(!
    resulterror_message(sql_error());
    ?>
    <center><h3><?php echo $firstName $lastName ?>, thank you for registering with us!</h3></center>
    <?php
        html_footer
    ();
    }
    switch(
    $action) {
    case 
    "register":
        
    create_account();
    break;
    default:
    html_header();
    register_form();
    html_footer();
    break;
    }
    ?>
    Last edited by 52designs; 03-11-2008 at 01:32 AM. Reason: forgot link

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Google "php +mysql +connect" or maybe "php +mysql +tutorial".

  • #3
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    http://www.tizag.com/mysqlTutorial/mysqlconnection.php
    Tizag's tutorials are very good so ide bookmark it

    -Adam
    Why not thank me?

    http://adamsworld.name


  •  

    Posting Permissions

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