Jump to content

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given


Alanp

Recommended Posts

Hello! every one.

 

I have my php-mysql codes bellow which gives the error

"Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\jopasy_community_2.2\includes\view.php on line 28"

 

bellow are the codes

 

<?php
    include 'connection.php';
    $con = mysql_connect($host,$user,$pwd);
    $db = mysql_select_db($database);
    
    include 'create_tables.php';
    
    $sql = 'SELECT name, qntitle, question  FROM questions';
    
    $retval = mysql_query( $sql, $con );
    if(! $retval )
    {
      die('Could not get data: ' . mysql_error());
    }
    while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
    {
    $qnabout=$row['qntitle'];
    
        echo "<b>Question: </b>{$row['question']} <br>".
         "<b>Asked by : </b> {$row['name']} <br> ".
         "<b>Question about: </b> {$row['qntitle']} <br><br> ".
         
         "<b>Answers</b> <br><br> ".
        
        $getanswer = ("SELECT answerdby, answer FROM answers WHERE qntitle ='".$qnabout."';");
        $answer = mysql_query( $getanswer, $con );
        
        while($ans = mysql_fetch_array($answer, MYSQL_ASSOC)) // THIS IS THE LINE WITH ERROR
        {
         echo "Answer : {$ans['answer']} <br> ".
         "<b>Answered by : </b> {$ans['answerdby']} <br> ".
         "--------------------------------<br><br><br><hr>";
        }
        
    }
    mysql_close($con);

?>

 

I dont know how to solve it. i need help plz

E: Propably SQL error, since the previous one is working

 

try this:

while($row = mysql_fetch_assoc($retval)) {
// do your stuff
}

Oh yeah, you shouldn't use mysql functions anymore. They're deprecated, use PDO or mysqli instead.

do  $answer = mysql_query( $getanswer, $con )  or die("MySQL ERROR: ".mysql_error());

 

So that the whole world sees your MySQL issues and all the sensitive information associated with them?  ::)

 

Internal error messages go into the log file, never on the user's screen. What you want is trigger_error().

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.