RE: [PHP] mysql_num_rows
| From: | John W. Holmes | Date: | Fri, 04 Apr 2003 22:28:21 +0000 |
| Subject: | RE: [PHP] mysql_num_rows | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-142449@lists.php.net to get a copy of this message | ||
> $department_name = $_POST['department_name'];
>
> $select_query = "SELECT * WHERE department_name = '$department_name'";
> $select_result = mysql_query($select_query, $db_connect);
> $select_total_rows = mysql_num_rows($select_result);
>
> if ($select_total_rows<1)
> {
> $insert_query = " insert into departments (department_name)
>
values
>
> ('$department_name')";
>
> mysql_query($insert_query, $db_connect) or die (mysql_error());
>
>
> I am getting back an error mysql_num_rows(): supplied argument is not
a
> valid MySQL result resource. I have looked over it again and again,
and
> can't see what is wrong. Can anyone else see where the problem might
be?
That means your query failed, generally. Check for mysql_error() after
you run your query to see what went wrong. For example in your SQL,
you're missing the "FROM table" portion of your query... oops!
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/