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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 />";

}

 

} ?>

 

 

Link to comment
Share on other sites

<?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);

 

 

 

 

 

 

Link to comment
Share on other sites

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 />";

 

 

} ?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

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.