Whats the proper way to check if mysql_query() returned any results?

后端 未结 8 1408
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-05 17:03

I tried what seemed like the most intuitive approach

$query = \"SELECT * FROM members 
          WHERE username = \'$_CLEAN[username]\'
          AND password =          


        
8条回答
  •  無奈伤痛
    2021-02-05 17:30

    What about this way:

    $query = "SELECT * FROM members WHERE username = '$_CLEAN[username]'
                                      AND password = '$_CLEAN[password]'";
    $result = mysql_query($query);
    $result = mysql_fetch_array($result);
    
    //you could then define your variables like:
    $username = $result['username'];
    $password = $result['password'];
    
    if ($result)
    { ...
    

    I like it because I get to be very specific with the results returned from the mysql_query.

    -Ivan Novak

提交回复
热议问题