Page 1 of 1

Strange $_POST behaviour?!

Posted: Sun May 23, 2010 5:44 pm
by mashruf
I have saved following code by login.php name and put that file on a server. But the problem is whenever I run the file it shows ''success!" allways. Why so? I can't understand.. Please help...

Code: Select all

<?php
      $con = mysql_connect("localhost","s_admin","habijabi");

      mysql_select_db("aluvhaji",$con);

        //Receive form data
        $uname = $_POST["titl"];
        $pword = $_POST["desc"];

	$value = mysql_query("select * from user where username = '$uname' and password='$pword'",$con);
		
        if($value)
        {
               echo "success!";
        }
        else die('Error: ' . mysql_error());
?>

Re: Strange $_POST behaviour?!

Posted: Sun May 23, 2010 6:20 pm
by requinix
mysql_query returns a resource for a SELECT query, not a boolean* or an array.

If you want to look at the number of rows use mysql_num_rows.


* Unless the query fails, for which you'll get false back.

Re: Strange $_POST behaviour?!

Posted: Mon May 24, 2010 1:14 pm
by mashruf
Thanks for the clarification. It speaks a lot...