...

View Full Version : MySQL and PHP trouble



moneybux
03-14-2008, 05:39 AM
This codes third line is give an error message on all pages of my web site.

<?
$sql = "SELECT * FROM tb_config WHERE item='click' and howmany='1'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>


The error message says the following

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/moneybux/public_html/index.php on line (number of line on page)

Can someone help me out to resolve this issue please.

_Aerospace_Eng_
03-14-2008, 06:56 AM
This is because your query is failing. You need to do some error checking.

<?php
$sql = "SELECT * FROM tb_config WHERE item='click' and howmany='1'";
$result = mysql_query($sql) or die('The error was: ' . mysql_error() .'<br>The query was: ' . $sql);
$row = mysql_fetch_array($result);
?>

phantom007
03-14-2008, 08:57 AM
Apparently there isnt any matching records in the table.

tomws
03-14-2008, 11:43 PM
Apparently there isnt any matching records in the table.

No matching records would still return a result set of zero and $result would be a valid result resource. Test it by running a query on an expected zero result set. Confirm by testing for mysql_num_rows($result) == 0;.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum