Listing Mysql Users

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
AlbinoJellyfish
Forum Commoner
Posts: 76
Joined: Sun Apr 04, 2004 7:39 pm

Listing Mysql Users

Post by AlbinoJellyfish »

I want to list all of the mysql users. This is my code.

Code: Select all

<?
error_reporting(E_ALL);
$username=$_POST['username'];
$password=$_POST['password'];
$db = mysql_connect("localhost",$username,$password);
mysql_select_db("mysql",$db);
if (! $db)
die("Couldn't connect to MySQL");
$query = "SELECT * FROM user SORT BY id DESC";
$result = mysql_query($query);
echo "<table border=1>\n";
echo "<tr><td>Host</td><td>Username</td><td>Select</td><td>Insert</td><td>Update</td><td>Delete</td><td>Create</td><td>Drop</td><td>Reload</td><td>Shutdown</td><td>Proccess</td><td>File</td><td>Grant</td><td>References</td><td>Index</td><td>Alter</tr>\n";

while ($myrow = mysql_fetch_row($result)) {
		printf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</tr>',
		$myrow[1], $myrow[2], $myrow[4], $myrow[5], $myrow[6], $myrow[7], $myrow[8], $myrow[9], $myrow[10], $myrow[11], $myrow[12], $myrow[13], $myrow[14], $myrow[15], $myrow[16], $myrow[17]);}
mysql_close($db);
?>
</table>

I get this error when I use the script.
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /usr/www/html/prototype/web_prototype/matt/admin/listusers.php on line 16
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Try this query:

Code: Select all

SELECT * FROM user ORDER BY user DESC
-- Scorphus
AlbinoJellyfish
Forum Commoner
Posts: 76
Joined: Sun Apr 04, 2004 7:39 pm

Post by AlbinoJellyfish »

Thank you. As you can see im just learning mysql.
Post Reply