Jump to content
MakeWebGames

Recommended Posts

Posted

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. :)

Posted

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.

Posted

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.

Posted
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. :)

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.   Paste as plain text instead

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