这是search.php的代码。我想从输入框中按日期搜索,如下所示。
<form action="visitor-print.php">
<div class="col-sm-3 text-center"><h3>Date</h3>
<input type="text" class="form-control" name="dat" placeholder="Enter Date">
<p class="help-block">Month Format 1,2,3,....29,30..</p>
<button class="btn btn-default"><span>Submit</span></button>
</div>
</form>
这是我的visitor-print.php代码,我在dat上得到未定义的索引错误(来自其他页面)
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db('visitor_list');
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = "SELECT * FROM list1 WHERE d1 = '". $_POST["dat"] . "' ";
$retval = mysql_query( $sql,$conn ) or die("Error: ".mysql_error($conn));
?>
<div class="container">
<h3 class="text-center">User Feed-Back Details</h3><br />
<div class="table-responsive" id="employee_table">
<table class="table table-bordered">
<tr>
<th width="10%">Visitor Name</th>
<th width="10%">Address</th>
<th width="10%">Area to Visit</th>
<th width="10%">Phone No.</th>
<th width="20%">Want to meet with </th>
<th width="50%">Purpose of meeting</th>
</tr>
<?php
while($row = mysql_fetch_array($retval,MYSQLI_BOTH))
{
?>
<tr>
<td><?php echo $row['nm']; ?></td>
<td><?php echo $row['add1']; ?></td>
<td><?php echo $row['area_vis']; ?></td>
<td><?php echo $row['y1']; ?></td>
<td><?php echo $row['app_ty']; ?></td>
<td><?php echo $row['no_per']; ?></td>
</tr>
<?php
}
?>
</table>
</div>
<div align="center">
<button name="create_excel" id="create_excel" class="btn btn-success">Create Excel File</button>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$('#create_excel').click(function(){
var excel_data = $('#employee_table').html();
var page = "excel.php?data=" + excel_data;
window.location = page;
});
});
</script>
问题: 注意:未定义的索引:第12行的D:\ wamp \ www \ radissun visitor \ visitor-print.php中的dat 并且没有显示来自mysql的数据
答案 0 :(得分:0)
您正在寻找的答案:您正在使用$ _POST - 这仅适用于具有method =“post”的表单。默认方法是GET - 所以你的变量是$ _GET []。您可以将html中的method参数设置为POST,也可以将PHP代码更改为GET。
但我必须指出,您的代码不适用于高效环境,因为它易受SQL注入攻击。见http://www.w3schools.com/sql/sql_injection.asp
答案 1 :(得分:0)
表格上的遗漏方法METHOD="POST"
NOTE:
如果你使用METHOD="POST"
你可以通过$ _POST获得价值[&#39; dat&#39;];如果您没有使用方法属性.FORM只是提交,因为您可以获得$ _GET [&#39; dat&#39;];
<form action="visitor-print.php" METHOD="POST" >
缺少表格提交
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="SUBMIT" >
(OR)
将TYPE="SUBMIT"
添加到按钮
<button TYPE="SUBMIT" class="btn btn-default"><span>Submit</span></button>