Jump to content

[SOLVED] Basic mySQL query error: mysql_numrows()


webmaster1

Recommended Posts

Hi All,

 

Can anybody spot whats discrepant with the below query? It works fine without the WHERE index = '134' part. It seems to be related to the number of rows.

 

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource

 

<?php
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM test WHERE index = '134' ORDER BY date";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>

It's either mysql_num_rows (current name) or mysql_numrows (old depreciated name.) Both work and an incorrect function name would not cause the error being output.

 

index is a reserved mysql keyword. Change your column name to something else or enclose it in back-ticks.

I've changed my primary key name from index to [index] in mySQL and my code.

 

I still recieve the same error:

 

<?php
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM test WHERE [index] = '134' ORDER BY date";
mysql_error();
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();
?>

 

revraz: Was mysql_error() meant to have a semi-colon? If yes, I recieve the exact same error as above. If no, I recieve a parse error.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.