Link to home
Create AccountLog in
Avatar of team2005
team2005

asked on

Compare two strings php

Hi!

Have this function, that compares two strings

function sjekkqrkode($lokasjon,$kundeid)
{
    $qrkode1 = hent_tmp_qrkode();
	$qrkode2 = hent_qrkode_lokasjon($kundeid,$lokasjon);
	
	if ( strcmp ( $qrkode1, $qrkode2) == 0  )
	{
	    echo 'HELT LIKE';
		die();
	    return 'like';
	}
	else
	{
	  echo 'ULIKE';
      die();	  
	  return 'ulike';
	}
}

Open in new window


function hent_tmp_qrkode()
{
        $sql = "SELECT tmpqr FROM qrcode";
        $res = mysql_query($sql);
        
        // IF THE QUERY SUCCEEDED
        if ($res)
        {
            // THERE SHOULD BE ONE ROW
            $num = mysql_num_rows($res);
            if ($num)
            {
                // RETRIEVE THE ROW FROM THE QUERY RESULTS SET
                $row = mysql_fetch_assoc($res);
                // STORE THE USER-ID IN THE SESSION ARRAY
                return $row["tmpqr"];
          
            }
			else
			{return 'xx';}
        }
		else
		{
		  return 'xx';
		}
}

Open in new window


function hent_qrkode_lokasjon($kundeid,$lokk)
{
        $sql = "SELECT qrcode FROM Lokasjoner WHERE Kunde_id = '$kundeid' and Lokasjons_id='$lokk'";
        $res = mysql_query($sql);
        
        // IF THE QUERY SUCCEEDED
        if ($res)
        {
            // THERE SHOULD BE ONE ROW
            $num = mysql_num_rows($res);
            if ($num)
            {
                // RETRIEVE THE ROW FROM THE QUERY RESULTS SET
                $row = mysql_fetch_assoc($res);

                // STORE THE USER-ID IN THE SESSION ARRAY
                return $row["qrcode"];
          
            }
			else
			{return 'yy';}
        }
		else
		{
		  return 'yy';
		}
}

Open in new window


Thie function ->  sjekkqrkode  always return ulike ?

Have checked my DB, and are 100% on that they are equal

What is wrong ?
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

Can you please post what is a sample value for $qrkode1 and $qrkode2 that you think they are equal in the DB,  and the return value for strcmp ($qrkode1, $qrkode2) for that?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
The first thing I would do is 'echo' the strings in the 'else' branch to see if I was getting what I thought I should be getting.
Avatar of team2005
team2005

ASKER

Used the query, that work :)
Cool - thanks for the points.