Author Topic: If statement always executes, even when it shouldn't  (Read 2221 times)

malicious

  • New Member
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
If statement always executes, even when it shouldn't
« on: May 12, 2004, 12:14:54 PM »
Can anyone point out to me why this keeps displaying the html located inside of if ( $auth = true ){}, even if wrong username/password combinations are used?  I'm sure it's something easy.  I just can't see it.


Code: [Select]
<?php 

$auth 
false
$user $_POST['sn'&#93;;
$pass $_POST['pw'&#93;;
if &#40;isset&#40; $user &#41; && isset&#40;$pass&#41;&#41; &#123; 

    
   
$db mysql_connect&#40; 'localhost', 'users', '*****' &#41; 
        
or die &#40; 'Unable to connect to server&#46;' &#41;; 

    

    
mysql_select_db&#40; 'pwtbl', $db &#41; 
        
or die &#40; 'Unable to select database&#46;' &#41;; 

    

    
$sql "SELECT * FROM pwtbl WHERE 
            txt_Screename = '
$user' AND 
            pw_pass = '
$pass'"

   

    
$result mysql_query&#40; $sql &#41; 
        
or die &#40; mysql_error&#40;&#41; &#41;; 

    

mysql_close&#40;&#41;;

    
&#46; 

    
$num mysql_numrows&#40; $result &#41;; 

    
if &#40; $num != 0 &#41; &#123; 

         

        
$auth true

    &
#125; 

&#125; 

if &#40; $auth = true &#41; &#123; 
echo '

A bunch of html

'

    

&
#125; 

else &#123; 
echo 'Authorization Required&#46;'
    exit; 

&
#125; 

?>

drewbee

  • Regular Member
  • **
  • Posts: 38
  • Karma: 0
    • View Profile
(No subject)
« Reply #1 on: May 12, 2004, 12:41:04 PM »
Weird... try doing this for me and see what it does..

   if ( $num > 0 ) {

         

        $auth = true;

    }
Rather then be like most men who want the world to know them; I want to know the world.

kcomer

  • Regular Member
  • **
  • Posts: 28
  • Karma: 0
    • View Profile
(No subject)
« Reply #2 on: May 12, 2004, 01:08:07 PM »
Your if statement says if $auth = true, that shoyuld really be $auth == true. Notice the double equal signs.

Keith