Page 1 of 1

Problem displaying results

Posted: Sun Dec 04, 2005 10:24 pm
by elAdi
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi all,

I used excactely this script on an other website, where it works perfectly well. Now I'm building a new site and it get the following error:

Code: Select all

Warning: mysql_fetch_array(): 4 is not a valid MySQL result resource in c:\wamp\www\growthring\cms\cmsUser.php on line 23
Here's the code of the php file:

Code: Select all

<?php
include("condata.php");
$dbh = mysql_connect ("$MySQLHost", "$MySQLUser", "$MySQLPW") or die ('I cannot connect to the database because: ' . mysql_error());
$sql = "SELECT userID, userProf, userClearance, userName FROM users";
$result = mysql_db_query("historing", $sql) or die("Invalid query: " . mysql_error());
// Resultat freigeben
mysql_free_result($result);
?>
<html>
<head>
<title>Growth Ring CMS - Enter New User</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../styles/styles_cms.css" rel="stylesheet" type="text/css">
</head>
<body>
USER ADMINISTRATION<br><br>
<a href="cmsUserNew.php">Click here</a> to add a new User!<br><br>
The following members are registered!<br><br>
<?php
var_dump($result); 
while ($reguser = mysql_fetch_array($result)) {
    echo $reguser['userID'];		     
}
// Verbindung schliessen
mysql_close($dbh);
?>
</body>
</html>
On the var_dump, I get:
resource(4) of type (Unknown)

What am I missing here. Help is much appreciated, because I really should push on this project. Just in case the environment:

All local:
Windows XP Prof
Apache/1.3.33 (Win32)
MySQL 5.0.15-nt
PHP 5.0.5

Thank you in advance!


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Dec 04, 2005 10:31 pm
by Jenk
Your script frees the result before you have used it.

You need to move:

Code: Select all

// Resultat freigeben
mysql_free_result($result);
To the end of your script.

OK

Posted: Sun Dec 04, 2005 10:38 pm
by elAdi
Thanks a lot. Strangly enough, it works with the other website!

Hm, I guess, I should stick to ColdFusion. lol. But my client didn't want to spend the money (hosting his own server).

Adrian