-1

IT 显示此错误警告:mysql_fetch_array() 期望参数 1 是资源,布尔值在第 18 行的 C:\wamp\www\ocwconnection\user\search.php 中给出

我不明白为什么会这样,因为我在许多文件中有相同的代码,但请帮助我谢谢


**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>
4

4 回答 4

0

我猜你的 mysql_query 有错误。请参阅 mysql_query 的文档。

对于 SELECT、SHOW、DESCRIBE、EXPLAIN 和其他返回结果集的语句,mysql_query() 成功时返回资源,错误时返回 FALSE。

所以,我猜你的 $query 变量中有一个 FALSE。

于 2013-11-01T11:07:52.347 回答
0

在获取行之前始终检查输出。您的查询中有一些错误。

尝试这样做:

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

这样做你会知道确切的错误。(避免使用mysql,而是使用mysqli

于 2013-11-01T11:11:10.597 回答
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 并使用准备好的语句。

于 2013-11-01T11:12:07.837 回答
-1

您忘记对此发表评论var_dump($query); exit;。在那之后,它应该工作。

于 2013-11-01T11:04:39.487 回答