No records returned problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

No records returned problem

Post 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
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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
}
?>
Image Image
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

Post 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
}
?>
Post Reply