I'm just beginning with PHP and came across something which is
frustrating me no end. I have a really simple script which given a
username will query the database and if it doesn't find a match will
then insert into the database. The problem I find is that even when
there is no data in the database to match the return from mysql_query
evaluates to true even though all the documentation and tutorials that I
have read say that mysql_query should return false when using a SELECT
query if there is no match. Am I missing something really simple here or
is there another explaination as to why this might be the case? The
following code snippet exhibits this behaviour. I am running the
following: Apache 2.0.54, PHP 5.0.5-2, MySQL 4.1.12.

    $username = "david";
    $conn = mysql_connect('localhost','user','pass');
    $sql = "SELECT * FROM users WHERE username='$username'";
    echo $sql."<br/>";
    $result = mysql_query($sql,$conn);
    echo $result."<br/.>";
    if (!$result)
        echo "No Match!<br/>";
        $row = mysql_fetch_array($result);
        while ($row)
            echo $row['username'].' -- '.$row['email'].'<br/>';
            $row = mysql_fetch_array($result);



PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to