Page 1 of 1

No records returned problem

Posted: Fri Aug 22, 2003 2:13 pm
by ericsodt
I am creating a logon page and I have some code that checks to see if any records are returned.

Now I use 'isset' to check but of course it gets set, so my quesion is, how do you check to see that a result set is returned without printing to screen. exampl:


$query = "select * from me_t where name=' ".$name." ' ";

if(isset($query)){
echo "query gets set";
}

Now I know I am using the wrong function but which one tells me that a record is returned?? I would send my whole code, however I am at work and do not have access to it at the moment

Posted: Fri Aug 22, 2003 3:09 pm
by phice
Try something like:

Code: Select all

<?
// Connect to MySQL
// Select table
$sql = mysql_query("SELECT * FROM `me_t` WHERE `name` = '{$name}'") or die("Unable to select from table `me_t`, error: " . mysql_error());

// Count results
$num_results = mysql_num_rows($sql);

// return true
if ($num_results > 0)
{
  // User is in database
} else {
 // User is not in database
}
?>

Posted: Fri Aug 22, 2003 3:28 pm
by ericsodt
When I go into production, I will make the transition into mySQL... but right now I am using an access database. :oops: Eventually I will make the switch, but for now I have to make due. Any other suggestions, besides get a new database???
phice wrote:Try something like:

Code: Select all

<?
// Connect to MySQL
// Select table
$sql = mysql_query("SELECT * FROM `me_t` WHERE `name` = '{$name}'") or die("Unable to select from table `me_t`, error: " . mysql_error());

// Count results
$num_results = mysql_num_rows($sql);

// return true
if ($num_results > 0)
{
  // User is in database
} else {
 // User is not in database
}
?>