PHP comparison giving me fits

heres my problem, I have an sql db biz_Client with 3 fields in it auth is Text, name is Text, option is Int

heres my sqldb code if anyone wants to try this and help me

CREATE TABLE IF NOT EXISTS `biz_Client` (
`auth`text NOT NULL,
 `name` text NOT NULL,
 `option` tinyint(4) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

on a previous page i ask for the “password” in a form as well as some other irrelevant stuff and pass it to a php page with the following code
[php]
$Auth=$_GET[‘pass’];
$result = mysql_query(“SELECT * FROM biz_Client WHERE $AUTH = auth”);
$row = mysql_fetch_array(result);
if ($Auth == $row[‘auth’])
{ echo “Auth Verified Continue”;}
else
{echo “Auth not verified”; }
[/php]

very simple straight forward code, but heres what happens

  1. if auth is a number and pass is the same number of any length it works perfectly
  2. if auth is a number and pass is a different number it works correctly telling me Auth not verified
  3. if auth is a letter say “a” and pass is the correct letter or different I always get Auth not verified
  4. if auth is a combination of Alpha{U/C} & Numbers no matter the input of pass I get Auth not verified

I have used trim on both $Auth and auth, I have tried using if ($Auth === $row[‘auth’]) and none of it works
I have also coded it this way with a second variable to use inside the comparison but still same results as above

[php]
$Auth=$_GET[‘pass’];
$result = mysql_query(“SELECT * FROM biz_Client WHERE $AUTH = auth”);
$row = mysql_fetch_array(result);
$searchVal = $row[‘auth’];
if ($Auth == $searchVal)
{ echo “Auth Verified Continue”;}
else
{echo “Auth not verified”; }
[/php]

Thanks for looking, hope someone can see where I’ve messed up. Please don’t try to recode the whole thing there is more involved using the query so switching it to a " if ($row) { etc…}" is not an option

The problem is your query

Try
[php]
$result = mysql_query(“SELECT * FROM biz_Client WHERE auth=’$AUTH’”) or die(mysql_error());
[/php]

Thanks for looking, isn’t it amazing how after you look at something for hours you just can’t get it right because of something real small.

I put the single quotes around $Auth in my code and it worked, Thanks Wilson

so now my correct WORKING Code is
[php]$Auth=$_GET[‘pass’];
$result = mysql_query(“SELECT * FROM biz_Client WHERE ‘$AUTH’ = auth”);
$row = mysql_fetch_array(result);
if ($Auth == $row[‘auth’])
{ echo “Auth Verified Continue”;}
else
{echo “Auth not verified”; }[/php]

haha yeah those small mistake are the hardest to find.

marked solved

Sponsor our Newsletter | Privacy Policy | Terms of Service