Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

num_row error

Status
Not open for further replies.

ja01

Technical User
Dec 14, 2005
48
US
I have the following script that is supposed to allow me to access a mysql database. Everything works until I get to line 41 $num = mysql_num_rows($result);
I get an error message Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Here is lines 38 through 42 of the script. Why am I getting the error message and what is the fix.
$query = "SELECT * from lines ORDER BY Year";
$result=mysql_query($query);

$num = mysql_num_rows($result);

mysql_close();
 
i believe you are using a reserved word in your query

try
Code:
$query = "SELECT * from lines ORDER BY `Year`";

jic: have you determined beyond doubt that you are connecting to the db ok?
 
I am sure I am connecting, here is the code up through the line that gives me trouble

<?php

//connect to server and select database
$conn = mysql_connect("localhost", "test1_admin", "admin") or die(mysql_error());
mysql_select_db("test1_database1",$conn) or die(mysql_error());

$display_block = "<h1><p>test Nu Pledge Lines</p></h1>
<p><h2>Updated July 31, 2006</h2></p>";


$query = "SELECT * from lines ORDER BY Year";
$result=mysql_query($query);

$num = mysql_num_rows($result);

mysql_close();
 
as posted. it's the backticks you need to fix.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top