SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    933
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow check user if exist?

    hi i know this is very basic,

    but i'm currently freakin out because for some reason my codes don't work.

    here is my codes below,
    Code:
    $query = "SELECT firstname, lastname FROM member WHERE firstname='$fname' AND lastname='$lname'";
    $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error());
    		$row = mysql_fetch_array($result);
    		$fname2 = $row['firstname'];
    		$lname2 = $row['lastname'];
    By the way i want to check the full name since the first and last name is in
    separate column.

    Is there something wrong with my codes?

    Can you show me your style please.

    Thank you.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What error are you getting?

    The first thing I always do to debug my MYSQL code is to echo out $query just before I execute it to ensure all the variables have been inserted correctly.

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $FirstName MySQL_Real_Escape_String($FirstName);
    $LastName MySQL_Real_Escape_String($LastName);
    $Query "SELECT 1 FROM users WHERE FirstName='{$FirstName}' AND LastName='{$LastName}'";
    $Result MySQL_Query($Query) or exit("Problem with the query: $query on line " __LINE__ '<br>' mysql_error());
    if(
    MySQL_Num_Rows($query) > 0){
        
    //User exists. $FirstName is already set to the firstname, $LastName is already set to the last name.
    }else{
        
    //user doesn't exist

    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    <?php
        $fname 
    "YourName";
        
    $lname "YourLastName";

        
    $query "SELECT firstname, lastname FROM member 
                WHERE firstname = '
    $fname' AND lastname = '$lname' LIMIT 1";
        
    $resultmysql_query($query) or die("Error: " mysql_error());
        
        if(
    mysql_num_rows($result) == 1){
            
    $row mysql_fetch_array($result);
            
    $fname2 $row['firstname'];
            
    $lname2 $row['lastname'];
        }else{
            echo 
    "No user found!";
        }
    ?>


Bookmarks

Posting Permissions

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