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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.