Jump to content


Photo

PHP error with mysql_fetch_array()


  • Please log in to reply
2 replies to this topic

#1 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 21 September 2006 - 11:50 PM

I get this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in myreports.php on line 45


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

<?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
    }
    ?>

Your help is greatly appreciated,

Thanks

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 September 2006 - 12:01 AM

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:
<?php
$query = "SELECT * FROM `bug_report` WHERE `username` = bug.submitter";
$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
?>

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

Ken

#3 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 22 September 2006 - 12:12 AM

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

   <?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
    }
    ?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users