blueman378 Posted April 5, 2008 Share Posted April 5, 2008 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? Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 check tablename u hve entered ............ Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 or check fieldname .... Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 thosee are fine, i ran it through php my admin and the query worked, and there is data in there Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 hve checked for database connection Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 yup its connected Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 then can u send ur code ... Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 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 Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 oops.its working perfectly ...for me .... Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 its working if i remove the if & else section ... Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 odd... well you can see it live at http://webspirited.com/games/index.php?action=1 Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 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 />"; } } ?> Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 tried it, same error Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 <?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); Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 nope just filled in all details again still same thing Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 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 />"; } ?> Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 still not wporking?...im seeing that in live.... then try for $row = mysql_fetch_array($result); Quote Link to comment Share on other sites More sharing options...
paul2463 Posted April 5, 2008 Share Posted April 5, 2008 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 Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 check ur database name Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 ah thanks, thats displaying a more logical error now, its saying no database is selected, yet it is filled out in constants.php... any ideas? Quote Link to comment Share on other sites More sharing options...
paul2463 Posted April 5, 2008 Share Posted April 5, 2008 and do you include constants.php in your index page? Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 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 Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 check constants.php file path...or try constants.php contents in index.php ... Quote Link to comment Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 got it atlast....... Quote Link to comment Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 sorry guys my bad, i forgot with my host you have to add a new user to every single database, you cant have a global sql user thats all it was ;P thanks for everyones help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.