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? Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/ Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 check tablename u hve entered ............ Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509862 Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 or check fieldname .... Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509863 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 Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509864 Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 hve checked for database connection Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509865 Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 yup its connected Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509866 Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 then can u send ur code ... Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509867 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 Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509869 Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 oops.its working perfectly ...for me .... Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509872 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 ... Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509873 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 Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509874 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 />"; } } ?> Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509875 Share on other sites More sharing options...
blueman378 Posted April 5, 2008 Author Share Posted April 5, 2008 tried it, same error Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509878 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); Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509880 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 Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509881 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 />"; } ?> Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509882 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); Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509884 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 Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509885 Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 check ur database name Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509886 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? Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509888 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? Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509890 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 Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509891 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 ... Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509892 Share on other sites More sharing options...
zenag Posted April 5, 2008 Share Posted April 5, 2008 got it atlast....... Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509895 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 Link to comment https://forums.phpfreaks.com/topic/99668-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-r/#findComment-509896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.