dual_alliance Posted September 21, 2006 Share Posted September 21, 2006 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 More sharing options...
kenrbnsn Posted September 22, 2006 Share Posted September 22, 2006 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 https://forums.phpfreaks.com/topic/21599-php-error-with-mysql_fetch_array/#findComment-96403 Share on other sites More sharing options...
dual_alliance Posted September 22, 2006 Author Share Posted September 22, 2006 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 https://forums.phpfreaks.com/topic/21599-php-error-with-mysql_fetch_array/#findComment-96406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.