Jump to content

Recommended Posts

Hi,

 

I'm a relative newbie to php but I've been programming in one language or another for 25+ years.

 

What I'm running into is a situation where I contruct an SQL query, call mysql_query, and I'm not getting a FALSE return when it should not be finding a record.

 

My query looks something like this:

 

SELECT dist_IdNum, dist_Active, dist_Company FROM Distributors WHERE dist_Login = 'badlogin'

 

The code snippet looks like this:

 

$result = mysql_query( $query, $link );
if ($result) print 'found the login';
else print 'login not found';

 

It doesn't matter what I enter for the login, the call to mysql_query never gives me a FALSE return.

 

Am I missing something really basic here?

 

Link to comment
https://forums.phpfreaks.com/topic/70578-solved-mysql_query-never-returning-false/
Share on other sites

and I'm not getting a FALSE return when it should not be finding a record.

 

If your query succeeds (record or not) you will get a result resource returned. Use mysql_num_rows. eg;

 

<?php

  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      // display records.
    } else {
      // no record found.
    }
  } else {
    // query failed.
  }

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.