472,101 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

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

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/scripts/07/view_users.php on line 15

Can anyone spot my error?!? Thanks.

<?php # Script 7.6 - view_users.php (2nd version after Script 7.4)
// This script retrieves all the records from the users table.

$page_title = 'View the Current Users';
include ('./includes/header.html');

// Page header.
echo '<h1 id="mainhead">Registered Users</h1>';

require_once ('./mysql_connect.php'); // Connect to the db.

// Make the query.
$query = "SELECT CONCAT(last_name, ', ', first_name) AS name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC";
$result = @mysql_query ($query); // Run the query.
$num = mysql_num_rows($result);

if ($num > 0) { // If it ran OK, display the records.

echo "<p>There are currently $num registered users.</p>\n";

// Table header.
echo '<table align="center" cellspacing="0" cellpadding="5">
<tr><td align="left"><b>Name</b></td><td align="left"><b>Date Registered</b></td></tr>
';

// Fetch and print all the records.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['dr'] . '</td></tr>
';
}

echo '</table>';

mysql_free_result ($result); // Free up the resources.

} else { // If it did not run OK.
echo '<p class="error">There are currently no registered users.</p>';
}

mysql_close(); // Close the database connection.

include ('./includes/footer.html'); // Include the HTML footer.
?>
Nov 9 '06 #1
2 18755
ronverdonk
4,258 Expert 4TB
When you suppress the error, you waill not get an error message. Replace with

[php]$result = mysql_query ($query)
or die("Query error: ". mysql_error());[/php]
and see what the message says.

Next time put your code between tags as stated in the Posting Guidelines!!

Ronald :cool:
Nov 9 '06 #2
Nert
64
try this one, if it didn't work i don't know what your problem was hehe(^_^)..

<?
$page_title = 'View the Current Users';
include ('./includes/header.html');

// Page header.
echo '<h1 id="mainhead">Registered Users</h1>';

require_once ('./mysql_connect.php'); // Connect to the db.

// Make the query.
$query = "SELECT CONCAT(last_name, ', ', first_name) AS name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC";
$result = mysql_query($query) or die(mysql_error()); // Run the query.
$num = mysql_num_rows($result);
echo "<p>There are currently $num registered users.</p>\n";

if($num != 0){
// Table header.
echo "<table align='center' cellspacing='0' cellpadding='5'>
<tr>
<td align='left'><b>Name</b></td>
<td align='left'><b>Date Registered</b></td>
</tr>";

// Fetch and print all the records.
while ($row = mysql_fetch_array($result)) {
echo "<tr>
<td align='left'>" .$row['name'] ."</td>
<td align='left'>" .$row['dr'] ."</td>
</tr>";
}
echo "</table>";

mysql_free_result ($result); // Free up the resources.

} else { // If it did not run OK.
echo '<p class="error">There are currently no registered users.</p>';
}

mysql_close(); // Close the database connection.

include ('./includes/footer.html'); // Include the HTML footer.
?>

--nert
Nov 10 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Willem Berendsen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.