2013-11-01 17 views
-1

其演示此錯誤 警告:mysql_fetch_array()預計參數1是資源,在布爾C中給出:\瓦帕\ WWW \ ocwconnection \用戶\ search.php中第18行如何解決對於MySQL這顯示錯誤獲取數組

我無法理解爲什麼會這樣,因爲我有很多文件相同的代碼,但請幫我謝謝


**search.php** 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Search results</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link rel="stylesheet" type="text/css" href="style.css"/> 
</head> 
<body> 
<?php 
    $con = mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error()); 
    $db = mysql_select_db("ocw_connection") or die(mysql_error()); 
    // var_dump($db); exit; 
    $sql = "SELECT * FROM ocwconnections WHERE FormDistributionDate BETWEEN `fromdate` AND `todate` "; 
    $query = mysql_query($sql); 
    var_dump($query); exit; 
    echo "<table>"; 

    echo "<thead><tr><td>Serial No.</td><td>Zone</td><td>Distrbuted Date</td><td>Form no.</td><td>Consumer Name</td><td>Address</td><td>Telephone No.</td><td>Completed Form Received Date</td><td>TLs Name</td><td>Date of Handover to TL</td><td>Site visit date by TL</td><td>Handover date to SPM</td><td>O&M Name</td><td>Handover date to O&M </td><td>Date of Estimate Prepared</td><td>Estimate Amount INR (Technical)</td><td>Date of Estimate recevied from O&M</td><td>Deposits/Other Chareges INR (Commercial)</td><td>Final Demand Amount INR</td><td>Date of submission for approved to delegate</td><td>Date of approval</td><td>Date of Demand Details given to Consumer</td><td>Demand Paid Date</td><td>Handover to O&M for Execuation</td><td>Connection Date</td><td>Date of Commencement of Water supply</td><td>Billig Started</td><td>Date provided to Billing Section for Entry</td><td>Date of Data Entry by Billing Section</td><td>Status</td><td>Reason</td><td>Comment</td><td>Ageing with CS</td><td>Ageing with O&M (Estimate)</td><td>Ageing with Delegate/EE</td><td>Ageing for Payment</td><td>Ageing with O&M (Connection)</td><td>Ageing with Commencement of Water</td><td>Ageing for Billing</td><td>Total Ageing</td><td>Recevied Month</td><td>Connection Month</td><td>CIN</td><td>ReceiptNumber</td> </tr></thead>"; 
    while($row = mysql_fetch_array($query)) 
    { 
     echo "<tr><td>$row[ID]</td><td>$row[ZoneID]</td><td>$row[FormDistributionDate]</td><td>$row[FormNo]</td><td>$row[ConsumerName]</td><td>$row[Address]</td><td>$row[TelephoneNo]</td><td>$row[CompletedFormReceivedDate]</td><td>$row[TLsName]</td><td>$row[DateOfHandoverToTL]</td><td>$row[SiteVisitDateByTL]</td><td>$row[HandoverDateToSPM]</td><td>$row[OMName]</td><td>$row[HandoverDateToOM]</td><td>$row[DateOfEstimatePrepared]</td><td>$row[EstimateAmountINRTechnical]</td><td>$row[DateOfEstimateReceviedFromOM]</td><td>$row[DepositsOtherCharegesINRCommercial]</td><td>$row[FinalDemandAmountINR]</td><td>$row[DateOfSubmissionForApprovedToDelegate]</td><td>$row[DateOfApproval]</td><td>$row[DateOfDemandDetailsGivenToConsumer]</td><td>$row[DemandPaidDate]</td><td>$row[HandoverToOMForExecuation]</td><td>$row[ConnectionDate]</td><td>$row[DateOfCommencementOfWaterSupply]</td><td>$row[BilligStarted]</td><td>$row[DateProvidedToBillingSectionForEntry]</td><td>$row[DateOfDataEntryByBillingSection]</td><td>$row[StatusID]</td><td>$row[Reason]</td><td>$row[Comment]</td><td>$row[AgeingWithCS]</td><td>$row[AgeingWithOMEstimate]</td><td>$row[AgeingWithDelegateEE]</td><td>$row[AgeingForPayment]</td><td>$row[AgeingWithOMConnection]</td><td>$row[AgeingWithCommencementOfWater]</td><td>$row[AgeingForBilling]</td><td>$row[TotalAgeing]</td><td>$row[ReceviedMonth]</td><td>$row[ConnectionMonth]</td><td>$row[CIN]</td><td>$row[ReceiptNumber]</td></tr>"; 
    } 
    echo "</table>"; 
?> 

</body> 
</html> 

**index.php** 

<?php 
//------------------------------------------------------------ 
// RESTRICT ACCESS TO PAGE 
//------------------------------------------------------------ 
require_once('../web.config.php'); require_once(ROOT_PATH.'global.php'); 
$auth_roles = array('owner','superadmin','administrator','member','user');// << add roles here 
require_once(ROOT_PATH.'modules/authorization/auth.php'); 
require_once(ROOT_PATH.'DBconnect.php'); 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Untitled Document</title> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script> 
    <link rel="stylesheet" href="/resources/demos/style.css" /> 
    <script language="JavaScript" type="text/javascript"> 
     $(function() { 
      $("#datepicker20").datepicker(({ dateFormat: "yy-mm-dd" })); 
      $("#datepicker21").datepicker(({ dateFormat: "yy-mm-dd" })); 
     }); 
    </script> 
</head> 

<body> 
    <form action="search.php" method="get"> 
     <input type="text" name="fromdate" id="datepicker20" /> 
     <input type="text" name="todate" id="datepicker21" /> 
     <input type="submit" value="Search" /> 
    </form> 
</body> 
</html> 
+0

在'mysql_query()'後面運行'echo mysql_error()'。請記住,'mysql_ *'函數已被棄用。 –

回答

0

你的SQL查詢是錯誤的。

SELECT * FROM ocwconnections WHERE FormDistributionDate BETWEEN `fromdate` AND `todate` 

被``包圍的字符串被視爲列名。看起來你需要一個變量。

$fromdate = $_GET['fromdate']; 
$todate= $_GET['todate']; 
$sql = "SELECT * FROM ocwconnections WHERE `FormDistributionDate` BETWEEN $fromdate AND $todate "; 

這應該工作(未測試)。

請記住,這會打開你的腳本到SQL注入。切換到mysqli_*函數或PDO並使用預準備語句。

+0

感謝它的工作... – MaheshDigarse

+0

但它不顯示來自數據庫表的數據是空的任何解決方案。 – MaheshDigarse

-1

你忘了評論此var_dump($query); exit;。之後,它應該工作。

+0

如果這是腳本甚至不運行'mysql_fetch_array()'命令的原因。 –

0

我想你的mysql_query中有一個錯誤。請參閱mysql_query文檔。

對於SELECT,SHOW,DESCRIBE,EXPLAIN和其他返回resultset的語句,mysql_query()返回成功的資源,錯誤時返回FALSE。

所以,我想你的$查詢變量有一個FALSE。

0

在獲取行之前總是檢查輸出。在查詢中有一些錯誤。

嘗試這樣做:

if(!$query) 
{ 
echo mysqli_error(); 
}else{ 
    while($row = mysqli_fetch_array($query)) 
    { 
    //fetch rows 
    } 

這樣做,你會了解確切的錯誤(避免使用mysql,而是使用mysqli