我有单独的代码,一个允许用户从数据库中选择id,另一个代码在按下提交按钮时显示其所有值。 : (eto.php)
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "auth";
// Create connection
$conn = new mysqli("localhost", "root", "", "auth");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id_no from employee ORDER BY id_no asc";
$result = $conn->query($sql);
?>
<form action="http://localhost/pdf2/id.php" method="POST" target="_blank">
Print By ID Number:
<select name="id" id="id" onchange="changeSelect(this.value)">
<?php while ($row = $result->fetch_array()) { ?>
<option value="<?php
echo"<input type=hidden name=id size=30 id=id value=$row[id_no] required>";
?>" >
<?php echo($row['id_no']); ?>
</option>
<?php } ?>
</select>
<input type="submit" name="submitID" value="Print"/>
</form>
<div id="demo"></div>
<script>
function changeSelect(value)
{
document.getElementById("demo").innerHTML = value
}
</script>
(打印表值的id.php --fpdf表单):
<?php
require('mysql_table.php');
if(isset($_POST['submitID']))
{
$id=$_POST['id'];
class PDF extends PDF_MySQL_Table
{
function Header()
{
//Title
$this->SetFont('Arial','',18);
$this->Cell(0,6,'Type of Leave',0,1,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}
mysql_connect('localhost','root','');
mysql_select_db('auth');
$pdf=new PDF();
//First table: put all columns automatically
$pdf->AddPage();
$pdf->AddCol('leave_id',20,'','C');
$pdf->AddCol('fullname',40,'Fullname');
$pdf->AddCol('type_of_leave',40,'Type of Leave','R');
$prop=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>2);
$pdf->Table("select leave_id, fullname, type_of_leave from application where id_no='$_POST[id]'",$prop);
$pdf->Output();
?>
按下提交按钮后,它会成功打印pdf,但表格的数据始终为空。 Mysql数据库不为空并且工作正常。这有什么问题?