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
    Mar 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Register Form code not working correctly

    Here is my registration form code. NOTE: I took out my phpMyAdmin username, password, and host name and replaced them with "N/A".
    PHP Code:
    <?php
        
    //Start session
        
    session_start();
        
        
    //Include database connection details
        
    require_once('config.php');
        
        
    //Array to store validation errors
        
    $errmsg_arr = array();
        
        
    //Validation error flag
        
    $errflag false;
        
        
    //Connect to mysql server
        
    $link mysql_connect("N/A""N/A""N/A");
        if(!
    $link) {
            die(
    'Failed to connect to server: ' mysql_error());
        }
        
        
    //Select database
        
    $db mysql_select_db("sources");
        if(!
    $db) {
            die(
    "Unable to select database");
        }
        
        
    //Function to sanitize values received from the form. Prevents SQL injection
        
    function clean($str) {
            
    $str = @trim($str);
            if(
    get_magic_quotes_gpc()) {
                
    $str stripslashes($str);
            }
            return 
    mysql_real_escape_string($str);
        }
        
        
    //Sanitize the POST values
        
    $fname clean($_POST['fname']);
        
    $lname clean($_POST['lname']);
        
    $email clean($_POST['email']);
        
    $password clean($_POST['password']);
        
    $password2 clean($_POST['password2']);
        
        
    //Input Validations
        
    if($fname == '') {
            
    $errmsg_arr[] = 'First name missing';
            
    $errflag true;
        }
        if(
    $lname == '') {
            
    $errmsg_arr[] = 'Last name missing';
            
    $errflag true;
        }
        if(
    $email == '') {
            
    $errmsg_arr[] = 'Email missing';
            
    $errflag true;
        }
        if(
    $password == '') {
            
    $errmsg_arr[] = 'Password missing';
            
    $errflag true;
        }
        if(
    $password2 == '') {
            
    $errmsg_arr[] = 'Confirm password missing';
            
    $errflag true;
        }
        if( 
    strcmp($password$password2) != ) {
            
    $errmsg_arr[] = 'Passwords do not match';
            
    $errflag true;
        }
        
        
    //Check for duplicate emails
        
    if($email != '') {
            
    $qry "SELECT * FROM members WHERE login='$email'";
            
    $result mysql_query($qry);
            if(
    $result) {
                if(
    mysql_num_rows($result) > 0) {
                    
    $errmsg_arr[] = 'Email already in use';
                    
    $errflag true;
                }
                @
    mysql_free_result($result);
            }
            else {
                die(
    mysql_error());
            }
        }
        
        
    //If there are input validations, redirect back to the registration form
        
    if($errflag) {
            
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
            
    session_write_close();
            
    header("location: index.php");
            exit();
        }

        
    //Create INSERT query
        
    $qry "INSERT INTO members(fname, lname, email, pswd) VALUES('$fname','$lname','$email','".md5($_POST['password'])."')";
        
    $result mysql_query($qry);
        
        
    //Check whether the query was successful or not
        
    if($result) {
            
    header("location: register-success.php");
            exit();
        }else {
            die(
    mysql_error());
        }
    ?>
    Now the reason I'm posting this thread, is because I try and register and I get the error saying: "Table 'sources.members' doesn't exist". What's sources.members? My database name is "sources" but I don't know what ".members" is. Can someone help?

  • #2
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    You're searching a database called 'members' for existing emails as below.

    PHP Code:
    $qry "SELECT * FROM members WHERE login='$email'"
    And again here.

    PHP Code:
    $qry "INSERT INTO members(fname, lname, email, pswd) VALUES('$fname','$lname','$email','".md5($_POST['password'])."')"

  • Users who have thanked Foster for this post:

    DarkArtsProdigy (03-23-2013)

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    lol I did not see that. Sorry I got the code from my friend. Thanks though!


  •  

    Tags for this Thread

    Posting Permissions

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