Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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