handling a SELECT that returns nothing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am writing a web php application that is processing a request form. There are multiple times when I need to check if a record exists (i.e. user record) and if so, check the inputted data against the data already in the database and confirm whether the inputted data should update the database.

I am getting stuck in my check of whether a record yet exists. I thought that $result in the code snippet below would be empty, so I thought I could use the empty() function in an if conditional. But a later conditional on the returned result of 0 never happened, so I echoed the $result of the mysql_query.

I have a completely empty database and my initial test should load my new record, but I am finding that the $result is being filled with

Resource id #4

from the mysql_query. Why? What does that mean? Why wouldn't it be empty? And more importantly, how do I this check properly?

Thanks,
Tim

<?php
function record_exist($select_value, $search_value, $table, $field) {

$query = "SELECT $select_value FROM $table WHERE $field = '{$search_value}'";

$result = mysql_query("SELECT $select_value FROM $table WHERE $field='{$search_value}'") or die(mysql_error());

   echo "$result"."<br>";

   if (empty($result)) {
      return 0;
   }
   else {
      return $result;
   }
}
?>

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

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux