mnaidis Posted May 17, 2012 Share Posted May 17, 2012 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)) { ?>   <b>Username:</b> <?php echo $d['username']; ?> <br />   <b>Level:</b> <?php echo $d['level']; ?> <br />   <b>Email:</b> <?php echo $d['email']; ?> <br />   <b>Admin level:</b> <?php echo $d['alevel']; ?> <br />   <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 More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 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)) { Link to comment https://forums.phpfreaks.com/topic/262668-mysql_fetch_assoc-and-num-rows-problem/#findComment-1346285 Share on other sites More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 Actually.... are you establishing a connection anywhere? mysql_connect() ?? Could explain why you're getting a boolean return instead of a resource. Link to comment https://forums.phpfreaks.com/topic/262668-mysql_fetch_assoc-and-num-rows-problem/#findComment-1346288 Share on other sites More sharing options...
mnaidis Posted May 17, 2012 Author Share Posted May 17, 2012 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. Link to comment https://forums.phpfreaks.com/topic/262668-mysql_fetch_assoc-and-num-rows-problem/#findComment-1346289 Share on other sites More sharing options...
mnaidis Posted May 17, 2012 Author Share Posted May 17, 2012 Oh, accidently I have named a field incorrectly, sorry for that! Solved. Link to comment https://forums.phpfreaks.com/topic/262668-mysql_fetch_assoc-and-num-rows-problem/#findComment-1346291 Share on other sites More sharing options...
smoseley Posted May 17, 2012 Share Posted May 17, 2012 Hah, that was actually my first guess, but your names below match the ones in the query. Link to comment https://forums.phpfreaks.com/topic/262668-mysql_fetch_assoc-and-num-rows-problem/#findComment-1346301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.