War_Hero Posted January 25, 2010 Posted January 25, 2010 Hi all. I've had a problem with a query or two, and I don't understand what's wrong. I've tried all that I know to fix it. But to me, the queries look correct. I'm getting this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in/usr/home/*****/domains/**********/public_html/changeuser.php on line 39 These are the lines I believe are causing the error: $select_admin = ("SELECT * FROM test_users WHERE user_level = 1"); $run_admin = mysql_query($select_admin) OR die(mysql_error()); and then further down the script: while($ad = mysql_fetch_assoc($run_admin)) { Before you ask, I have got a table called test_users, and a field called user_level. And there is at least one user in there who has a user_level of 1. :P Could someone please explain to me what is wrong with the above queries, or what I am missing? Other queries in my script are structured like this and work perfectly. Any help will be highly appreciated. Thank you. :) Quote
Magictallguy Posted January 25, 2010 Posted January 25, 2010 Those snippets look fine to me, please post at least 10 lines either of each line posted. Quote
bluegman991 Posted January 25, 2010 Posted January 25, 2010 first try removing the "()" from $select_admin if that doesnt work post 5 lines before and after where u got the error from Quote
War_Hero Posted January 25, 2010 Author Posted January 25, 2010 The lines above and below the green and red snipets: <?php include "admin_globals_test.php"; $ad_password = ("SELECT t_password FROM administrators"); $apass = mysql_query($ad_password); $p = mysql_fetch_assoc($apass); $select_admin = ("SELECT * FROM test_users WHERE user_level = 1"); $run_admin = mysql_query($select_admin) OR die(mysql_error()); $select_users = ("SELECT ID, forename, surname, login_name FROM test_users WHERE user_level != 1"); $run_users = mysql_query($select_users) OR die(mysql_error()); $count_users = mysql_num_rows($run_users); switch($_GET['action']) { case 'submit': submit(); break; default: index(); break; } And the lines above and below the blue snipet: Â function index() { global $db, $ud, $uID; print " <h3 />Change User Level</h3> <hr /> Here you can change the user level of a member to make them an administrator. Below is a list of the current administrators and a list of the current users. <table width = '70%' class = 'table2' /> <tr /> <th />ID</th> <th />Forename</th> <th />Surname</th> <th />Login Name</th> </tr>"; while($ad = mysql_fetch_assoc($run_admin)) { print " <tr /> <td />{$ad['ID']}</td> <td />{$ad['forename']}</td> <td />{$ad['surname']}</td> <td />{$ad['login_name']}</td> </tr>"; } Both include the snipets posted in the first post. I can't see what's wrong. Maybe I've been looking at it for too long, I don't know. Quote
Joshua Posted January 25, 2010 Posted January 25, 2010 You have the fetch array in a function and it's not going to call to something not in the function :P try putting the query under the function bit, should work fine. Quote
bluegman991 Posted January 25, 2010 Posted January 25, 2010 i see the problem in function index() change global $db, $ud, $uID; to global $db, $ud, $uID, $run_admin; Quote
War_Hero Posted January 25, 2010 Author Posted January 25, 2010 You have the fetch array in a function and it's not going to call to something not in the function :P try putting the query under the function bit, should work fine.Thank you. :) It's worked now. I guess that's what I get for not doing PHP for over 5 months. Need to get back up to scratch, me thinks. haha Thanks again. :) Quote
Joshua Posted January 25, 2010 Posted January 25, 2010 Np that used to bug me at times, used to forget to add $db to the function class then bug out when $db was "unknown" lol. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.