i have and error :

mysql_fetch_array() expects parameter 1 to be resource, boolean

what should i do??where is the problem..??please suggest..Thank you in advance..

Recommended Answers

All 12 Replies

Can you please post your php code, because this is a problem with your mysql statement. Thanks

below are the codes....

if (!isset($_GET['txtKeyword']))
{
    //Instruction if $_POST['value']doesnt exist
    $_GET['txtKeyword']="%";
}

if($_GET["txtKeyword"] != "")
{
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("mydatabase");
// Search By Name or Email
$strSQL = "SELECT * FROM proposals WHERE (pro_name LIKE '%".$_GET["txtKeyword"]."%' or pro_company LIKE '%".$_GET["txtKeyword"]."%')";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);

if (!isset($_GET['Page']))
{
    //Instruction if $_POST['value']doesnt exist
    $_GET['Page']="%";
}

$Per_Page = 4;   // Per Page

$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}

$Prev_Page = $Page-1;
$Next_Page = $Page+1;

$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}

$strSQL .=" order  by pro_id ASC LIMIT $Page_Start , $Per_Page";
$objQuery  = mysql_query($strSQL);

?>
<table width="600" border="1">
      <tr>
        <th width="40"> <div align="center"><font color="blue" size="3">Proposal ID </font></div></th>
        <th width="98"> <div align="center"><font color="blue" size="3">Proposal Name </font></div></th>
        <th width="80"> <div align="center"><font color="blue" size="3">Company </font></div></th>
        <th width="97"> <div align="center"><font color="blue" size="3">Proposal Date </font></div></th>
        <th width="59"> <div align="center"><font color="blue" size="3">Proposal Status</font></div></th>
        <th width="60"> <div align="center"><font color="blue" size="3">File</font></div></th>
        <th width="71"> <div align="center"><font color="blue" size="3">Proposal by </font></div></th>
      </tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
        <td><div align="center"><?=$objResult["pro_id"];?></div></td>
        <td><div align="center"><?=$objResult["pro_name"];?></div></td>
        <td><div align="center"><?=$objResult["pro_company"];?></div></td>
        <td><div align="center"><?=$objResult["pro_date"];?></div></td>
        <td><div align="center"><?=$objResult["pro_status"];?></div></td>
        <td><div align="center"><a href="<?=$objResult["pro_file"];?>">DOWNLOAD</a></div></td>
        <td><div align="center"><?=$objResult["pro_by"];?></div></td>
      </tr>
      <?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
}

for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
}

mysql_close($objConnect);
}
?>
</body>
</html>

this is the error :

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\CDMS\proposal2.php on line 79

there is also :

br /><b>Notice</b>: Undefined index: txtKeyword in <b>C:\xampp\htdocs\CDMS\proposal2.php</b> on line <b>10</b><br />

in the textbox..

From what i see, you have the connection, but you need to include the variable into the mysql_select_db

$objDB = mysql_select_db("mydatabase", $objConnect);

Second, make sure to difine txtKeyword. just add $txtKeyword = $_GET['textKeyword']. I would just make one if statement.

if (!isset($_GET['txtKeyword'])) {
    if($_GET["txtKeyword"] != "") {
        $txtKeyword = "%"
    }
    // rest of connection

Also, make sure you know the difference from $_GET and $_POST. To really test it, just have the connection by its self just to make sure everything is ok. I hope this helped.

@fobos :

Thanks..but it dosent work..

any other suggestion??

you should check if $_GET["txtKeyword"] is set.
see you code in line 7 if($_GET["txtKeyword"] != "")

error will occur if you will try to read or put this index to a condition becuase this index might not be found..

as your code says there will be an instance that if($_GET["txtKeyword"] != "") will be empty so.. check first if it is set

if (!isset($_GET['txtKeyword']))
{
//Instruction if $_POST['value']doesnt exist
$_GET['txtKeyword']="%";
}
if($_GET["txtKeyword"] != "")
{ set

from your line of codes

you can do this instead: put $_GET["txtKeyword"] to a variable then check if its empty like this.

    $txtKeyword = (!isset($_GET['txtKeyword']))?"%":"";

    if($txtKeyword!= "")
    {  #..... preceeding code
Member Avatar for diafol

It usually means that your query is wrong. Echo the query to the screen and copy/paste it into the sql window of phpmyadmin. See what it gives you.

yah diafol is correct
or see this line from your code $objQuery = mysql_query($strSQL); insert die(mysql_error())
so it looks like this $objQuery = mysql_query($strSQL) or die(mysql_error());

The code on lines 16 to 20 is a bit suspicious:

if (!isset($_GET['Page']))
{
    //Instruction if $_POST['value']doesnt exist
    $_GET['Page']="%";
}

$_GET['Page'] is supposed to be an integer, isn't it? In some circumstances the $Page variable could be assigned a value of % and the query would fail since $Page_Start and $Per_Page wont get calculated correctly:

$strSQL .=" order by pro_id ASC LIMIT $Page_Start , $Per_Page";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.