/    Sign up×
Community /Pin to ProfileBookmark

while($result2 = mysql_fetch_assoc($sql2)) problem

is this wrong? it did work then with out doing anything to it(i think) it came up with this
[b]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/sheldon/public_html/test/mva/viewuser.php on line 13[/b]

here is the code below

[code=php]<?
//INCLUDE THE HEADER – HEADER CONTAINS CONNECTTION AND SESSION START
include(“header.php”);
?>

<p class=”header”>All Members</p>
<?
//SQL QUERY TO SELECT ALL OF THE USERS
$sql2 = “SELECT * FROM users”;
$sql2 = mysql_query($sql2);

//WHILE USERS ARE IN THE DATABASE DO THE FOLLOWING
while($result2 = mysql_fetch_assoc($sql2)) {

//print user information
echo(“<span class=nav />Id:</span />{$result2[‘id’]} –
<span class=nav />Name:</span />{$result2[‘name’]} –
<span class=nav />email:</span />{$result2[’email’]} –
<span class=nav />username:</span />{$result2[‘username’]} –
<span class=nav />passowrd:</span />{$result2[‘password’]}”);
?>
</p>

<?
//END WHILE
}

//INCLUDE FOOTER
include(“footer.php”);
?>[/code]

Thanks

Sheldon

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 03.2005 — When you see that "not a valid MySQL resource" error, that mean your query failed (or you made a typo entering the variable name you used to capture the return value of the mysql_query() call.) In this case, either you did not successfully connect to the database (which I see no code for, so it might be in the header.php include?), or there was a syntax error in the query (which looks OK to me).

It's always a good idea to check the result of your mysql_query. I ususally so something simple like this when debugging, then maybe put in more robust error-handling later:
[code=php]
$query = "SELECT * FROM table";
$result = mysql_query($query) or die("Query Failed: " . mysql_error() . " - " . $query);
[/code]

This way, if the query fails, it prints out the MySQL error message and the actual text of the query so I have half a chance of figuring out what happened.
Copy linkTweet thisAlerts:
@SheldonauthorAug 03.2005 — cheers Nog Dog, it was a connection to the db problem.
×

Success!

Help @Sheldon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...