Jump to content

mysql_fetch_assoc and num rows problem.


mnaidis

Recommended Posts

I got this code at the top:

<?php
require_once("configuration.php");
$uid = $_GET['uid']; ?>

 

And another main one:

<?php
if(isset($_GET['uid']))
{ 

$d = "";
$query = mysql_query("SELECT `username`,`level`,`email,`,`alevel`,`tester` FROM `users` WHERE `id`='$uid'");
if(!mysql_num_rows($query))
echo "No user.";
while($d = mysql_fetch_assoc($query))
{
?>
&nbsp <b>Username:</b> <?php echo $d['username']; ?> <br />
&nbsp <b>Level:</b> <?php echo $d['level']; ?> <br />
&nbsp <b>Email:</b> <?php echo $d['email']; ?> <br />
&nbsp <b>Admin level:</b> <?php echo $d['alevel']; ?> <br />
&nbsp <b>Tester:</b> <?php echo $d['tester']; ?> 
<?php } } ?>
</font>
</div>
</center>

 

Now I get this error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\learning\viewuser.php on line 20
No user.
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\learning\viewuser.php on line 22

 

How can I fix it?

Link to comment
https://forums.phpfreaks.com/topic/262668-mysql_fetch_assoc-and-num-rows-problem/
Share on other sites

First....

 

$uid = mysql_real_escape_string($_GET['uid']);

 

 

 

Then...

 

 

$d = "";

$results = mysql_query("SELECT `username`,`level`,`email,`,`alevel`,`tester` FROM `users` WHERE `id`='$uid'");

if(!$results || !mysql_num_rows($results))

echo "No user.";

else

while($d = mysql_fetch_assoc($results))

{

First....

 

$uid = mysql_real_escape_string($_GET['uid']);

 

 

 

Then...

 

 

$d = "";

$results = mysql_query("SELECT `username`,`level`,`email,`,`alevel`,`tester` FROM `users` WHERE `id`='$uid'");

if(!$results || !mysql_num_rows($results))

echo "No user.";

while($d = mysql_fetch_assoc($results))

{

Actually.... are you establishing a connection anywhere?  mysql_connect() ??  Could explain why you're getting a boolean return instead of a resource.

 

It still says:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\learning\viewuser.php on line 22

 

And it says that the user doesn't exist, and it does.

 

And yeah, I have a connection.

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.