我知道这是一个经常被问到的问题,但是我试图在现有的代码上添加一些代码,让所有POST都能正常工作,只是我添加的不是,我尝试了大多数步骤,但是没有用, 我收到错误消息
注意:未定义的索引:第19行的C:\ xampp \ htdocs \ water_inventory \ production \ fetch_Cust_WaterBillPay.php中的pay_date_from
通知:未定义的索引:第21行的C:\ xampp \ htdocs \ water_inventory \ production \ fetch_Cust_WaterBillPay.php中的pay_date_from_to
这是我的代码:
<form id="demo-form2" class="form-horizontal form-label-left" action="fetch_Cust_WaterBillPay.php" method="POST">
<div class="form-group">
<label class="col-md-2">Pay Date From </label>
<div class="col-md-3">
<input type="date" id="pay_date_from" name="pay_date_from" class="form-control col-md-7 col-xs-12">
</div>
<label class="col-md-2">To</label>
<div class="col-md-3">
<input type="date" id="pay_date_to" placeholder="Enter Current Reading" name="pay_date_from_to" class="form-control col-md-7 col-xs-12">
</div>
<div class="col-md-2">
<input type="submit" class="btn btn-block btn-primary searchDept" style="margin-left: 3%;" value="Search"></div>
</div>
<br><hr>
<div id="result"></div><div style="clear:both"></div>
</form>
我的fetch_Cust_WaterBillPay.php:
<?php
session_start();
include './chklog.php';
include './db_config.php';
if ((!isset($_SESSION['first_name']) == true)) {
unset($_SESSION['first_name']);
}
$logged = $_SESSION['first_name'];
if(isset($_POST['submit']))
{
//if(isset($_POST['pay_date_from']))//Tried these
$pay_from=$_POST['pay_date_from'];
//if(isset($_POST['pay_date_from_to']))
$pay_to=$_POST['pay_date_from_to'];
$branch_name = $_SESSION['branch_name'];
}
?>
在此行出现错误:
<?php
$res1 =mysqli_query($con, "SELECT cust_id,customer_name,meter_no,created_on,invoice_month,invoice_no,amount_paying,mode_of_payment FROM `wb_customer_payment` WHERE branch_name='$branch_name' and created_on>='$pay_from' and created_on<='$pay_to' order by created_on desc");//Getting error here
while($data = mysqli_fetch_array($res1))
{
echo "<tr>"
. "<td>".$data['customer_name']."</td>"
. "<td>".$data['meter_no']."</td>"
. "<td>".$data['created_on']."</td>"
. "<td>".$data['invoice_month']."</td>"
. "<td>".$data['invoice_no']."</td>"
. "<td>".$data['amount_paying']."</td>"
. "<td>".$data['mode_of_payment']."</td>"
. "<td> <a href='water_bill_detail.php?cust_id=".$data["cust_id"]."' class='btn btn-primary btn-xs' role='button'><i class='fa fa-user'></i> Details</a></td>"
. "</tr>";
}
?>
更新:
我在检查为空之前声明了变量
$pay_from='';
$pay_to='';
但是,现在没有错误,但是我没有得到值。甚至URL都没有传递值。
我不确定我缺少什么。谢谢
答案 0 :(得分:0)
不是直接从用户输入字段中使用日期,而是将其转换为正确的格式
使用方式
if(isset($_POST['submit']))
{
$pay_from = date('Y-m-d',strtotime($_POST['pay_date_from']));
$pay_to = date('Y-m-d',strtotime($_POST['pay_date_from_to']));
$branch_name = $_SESSION['branch_name'];
}