Jump to content

Problem with SQL in PHP


GoodVibe

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/260360-problem-with-sql-in-php/
Share on other sites

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?

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.