team2005
asked on
Compare two strings php
Hi!
Have this function, that compares two strings
Thie function -> sjekkqrkode always return ulike ?
Have checked my DB, and are 100% on that they are equal
What is wrong ?
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';
}
}
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';
}
}
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';
}
}
Thie function -> sjekkqrkode always return ulike ?
Have checked my DB, and are 100% on that they are equal
What is wrong ?
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.
ASKER
Used the query, that work :)
Cool - thanks for the points.