www.webdeveloper.com
Results 1 to 4 of 4

Thread: plz help.. urgent PHP & CSV

  1. #1
    Join Date
    Dec 2006
    Posts
    115

    Question plz help.. urgent PHP & CSV

    hi all

    i have below php code which check the user name from a CSV file...

    I want to check from sql database... i m not getting any clue how to do it.. plz help

    PHP Code:
    <?
    $username 
    $_POST['username']; // get the username
    $username trim(htmlentities($username)); // strip some crap out of it
    $file '/folder/data.csv'// Here's the file. Notice the full path.

    echo check_username($file,$username); // call the check_username function and echo the results.

    function check_username($file_in,$username){
        
    $username=strtolower($username);
        
    $file file($file_in);
        foreach (
    $file as $line_num => $line) {
            
    $line explode(',',$line);
            
    $user trim(str_replace('"','',$line[0]));
            if(
    $username == strtolower($user)){
                return 
    '<span style="color:#f00">Username Unavailable</span>';
            }
        }
        return 
    '<span style="color:#0c0">Username Available</span>';
    }
    ?>

  2. #2
    Join Date
    Apr 2006
    Posts
    56
    http://ca.php.net/mysqli

    ^^^ that should tell you everything you'll want to know as far as the PHP side of it goes.

  3. #3
    Join Date
    Dec 2006
    Posts
    115
    i m not understanding wat r u pointing me to....

    plz can u replace the csv function with sql query???

    regards

  4. #4
    Join Date
    Mar 2007
    Location
    Pakistan
    Posts
    75
    PHP Code:
    <?php
    $username 
    $_POST['username']; // get the username
    $username trim(htmlentities($username)); // strip some crap out of it
    $dbinsmysql_connect("localhost""dbuser""dbpass"); // databse instence

    echo check_username($dbins,$username); // call the check_username function and echo the results.

    function check_username($dbins,$username){
        
    $username=strtolower($username);
        
    $sql "SELECT `username` FROM dbname.table WHERE `username`=$username";
        
    $qry mysql_query($sql$dbins);
        
    $num mysql_num_rows($qry);
            if(
    $num 0){
                return 
    '<span style="color:#f00">Username Unavailable</span>';
            }
        }
        return 
    '<span style="color:#0c0">Username Available</span>';
    }
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles