Jump to content

Archived

This topic is now archived and is closed to further replies.

dual_alliance

PHP error with mysql_fetch_array()

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.