GoodVibe Posted April 4, 2012 Share Posted April 4, 2012 Hows it going guys. I am currently having a problem. I had a program that worked. I migrated the website and now the program is broken. Any time i try to run it, i get this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/thegoo20/public_html/class/wordgame/wordgame.php on line 31 Here is the code at that point: function changeword(){ $result = mysql_query("Select words from CurrentWords"); $totalwords = array(); while ($row = mysql_fetch_array($result)){ $totalwords[] = $row["words"]; } $_SESSION['word'] = $totalwords[rand(0, count($totalwords)-1)]; $_SESSION['scrambled'] = str_shuffle($_SESSION['word']); } where line 31 is the while statement. Any help would be appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260360-problem-with-sql-in-php/ Share on other sites More sharing options...
Maq Posted April 4, 2012 Share Posted April 4, 2012 This error is usually caused because your SQL is invalid. Try changing this line to: $result = mysql_query("Select words from CurrentWords") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/260360-problem-with-sql-in-php/#findComment-1334456 Share on other sites More sharing options...
GoodVibe Posted April 4, 2012 Author Share Posted April 4, 2012 Ok. running that gives me the error: No database selected. If I go to my connection file, this is the code: <?php //Connect to DB $con = mysql_connect("localhost","thegoo20_user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("thegoo20_wordgame", $con); ?> When i run this file by itself, it does not give me any sql errors, so I thought that it was working fine. Maybe I am missing something? Quote Link to comment https://forums.phpfreaks.com/topic/260360-problem-with-sql-in-php/#findComment-1334459 Share on other sites More sharing options...
GoodVibe Posted April 4, 2012 Author Share Posted April 4, 2012 I found the error, and it ended up being that i had not authorized that user to access the database. Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/260360-problem-with-sql-in-php/#findComment-1334462 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.