Jump to content

PHP error with mysql_fetch_array()


dual_alliance

Recommended Posts

I get this error:[quote]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in myreports.php on line 45[/quote]

I think it could be because of the way l have set out my PHP code.  The code l have near line 45 is:

[code=php:0]<?php
    // Read information from MySQL database
$result = mysql_query("SELECT * FROM 'bug_report' WHERE '$username' = bug.submitter");
while ($row = mysql_fetch_array($result)){ <-- Line 45
?>
    <tr>
<td><?php echo $rows['bug.id']; ?></td>
<td><?php echo $rows['bug.date']; ?></td>
<td><?php echo $rows['bug.title']; ?></td>
<td><?php echo $rows['bug.description']; ?></td>
<td><?php echo $rows['bug.urgency']; ?></td>
  </tr>
<?php
    }
    ?>[/code]

Your help is greatly appreciated,

Thanks
Link to comment
https://forums.phpfreaks.com/topic/21599-php-error-with-mysql_fetch_array/
Share on other sites

You are using the wrong types of quotes, in your query, they should be backticks. And I don't think you should have a dollar sign on the "username" field. Change those lines to:
[code]<?php
$query = "SELECT * FROM `bug_report` WHERE `username` = bug.submitter";
$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
?>[/code]

Using the "or die" clause will let you see any sytax errors that you might not see otherwise.

Ken
Thankyou very much kenrbnsn for your speedy reply and help.  It works perfectly now, l just edited it so it is now:

[code=php:0]  <?php
    // Read information from MySQL database
    $query = "SELECT `bug.id`, `bug.date`, `bug.title`, `bug.description`, `bug.urgency` FROM `bug_report` WHERE `bug.submitter` = '$username' ";
$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
while ($row = mysql_fetch_array($result)){
?>
    <tr>
<td><?php echo $row['bug.id']; ?></td>
<td><?php echo $row['bug.date']; ?></td>
<td><?php echo $row['bug.title']; ?></td>
<td><?php echo $row['bug.description']; ?></td>
<td><?php echo $row['bug.urgency']; ?></td>
</tr>
<?php
    }
    ?>[/code]

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.