Jump to content

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result r...


blueman378

Recommended Posts

hi guys, well heres my query:

$result = mysql_query("SELECT * FROM users WHERE username='admin'");
while ($row = mysql_fetch_assoc ($result)) {

  echo $row['username'] . " " . $row['useremail'];
  echo "<br />";
  }

 

and heres the error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/webspiri/public_html/games/index.php on line 35

 

any ideas?

index.php

<?php include("includes/constants.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>WS Games - Provided by Web Spirited</title>
<meta name="keywords" content="Games Web Spirited Design" />
<meta name="description" content="flash games site provided by webspirited.com" />
<link href="default.css" rel="stylesheet" type="text/css" /></head>
<body>
<div id="logo">
<h1><a href="#">WS Games</a></h1>
<h2><a href="http://www.webspirited.com/">By Web Spirited</a></h2>
</div>
<div id="menu">
<ul>
	<li class="active"><a href="#" title="">Homepage</a></li>
	<li><a href="#" title="">Link1</a></li>
	<li><a href="#" title="">Link2</a></li>
	<li><a href="#" title="">Link3</a></li>
	<li><a href="#" title="">Link4</a></li>
	<li><a href="#" title="">Link5</a></li>
</ul>
</div>
<div id="wrapper">

<?php if($_GET['action'] == "")
{
include("main.php");
}
else
{
$result = mysql_query("SELECT * FROM users WHERE username='admin'");
while ($row = mysql_fetch_assoc($result)) {

echo $row['username'] . " " . $row['useremail'];
echo "<br />";
}

} ?>

</div>
<div id="footer">
<p id="legal">Copyright © 2007 Web Spirited. All Rights Reserved.</p>
<p id="links"><a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a> | Designed by <a href="http://www.webspirited.com/">Web Spirited</a>.</p>
</div>
</body>
</html>

 

constants.php

<?
// database connection
define("DB_SERVER", "localhost");
define("DB_USER", "xxxxxx");
define("DB_PASS", "xxxxxx");

//database table names
define("TABLE_USERS", "users");

$con = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("xxxxxx", $con);

?>

 

cheers

 

try this....

 

<?

$result = mysql_query("SELECT * FROM users WHERE username='admin'");

 

if($_POST["submit"]=='submit')

{include("main.php");

 

}

else

{

 

while ($row = mysql_fetch_assoc($result)) {

 

echo $row['username'] . " " . $row['useremail'];

echo "<br />";

}

 

} ?>

 

 

<?php

 

$result = mysql_query("SELECT * FROM users WHERE username='admin'");

 

if($_GET['action'] == "")

{

include("main.php");

}

else

{

 

while ($row = mysql_fetch_assoc($result)) {

 

echo $row['username'] . " " . $row['useremail'];

echo "<br />";

}

 

} ?>

 

or else ..

it might be ur constants.php page error

 

define("DB_SERVER", "localhost");

define("DB_USER", "xxxxxx");

define("DB_PASS", "xxxxxx");

 

//database table names

define("TABLE_USERS", "tablename");

 

$con = mysql_connect(DB_SERVER, DB_USER, DB_PASS);

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }mysql_select_db("databasename", $con);

 

 

 

 

 

 

try this.........

<?php

 

 

$result = mysql_query("SELECT * FROM users WHERE username='admin'");

 

 

if($_GET['action'] == "")

{

include("main.php");

}

else

{

$row = mysql_fetch_assoc($result);

 

echo $row['username'] . " " . $row['useremail'];

echo "<br />";

 

 

} ?>

 

try getting mysql to answer the problem for you.....it has tried by telling you that "Topic: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource" in other words the query has FAILED

 

try

$result = mysql_query("SELECT * FROM users WHERE username='admin'") or die ("Error in query" . mysql_error());

 

and see what it says is wrong

if i try to export the database i get:

Database: `webspiri_games`

and im my constants.php i have:

<?
// database connection
define("DB_SERVER", "localhost");
define("DB_USER", "xxxx");
define("DB_PASS", "xxxx");

//database table names
define("TABLE_USERS", "users");

$con = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }mysql_select_db("webspiri_games", $con);

?>
so it should be working...

and yeah i do include it right at the top

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.