我一直在这个网站上工作,打印提交它们的用户的表格。我使用按钮'视图表单'通过FPDF生成表单的PDF。 我的问题是我无法打印出我点击的表格。相反,已生成的最后一个表单已生成。 这是代码: Homepage.php:
<?php
$connection = mysqli_connect('localhost','root','','logindb1');
$output='';
if(isset($_POST['submit1'])){
// storing session
$username = $_SESSION['username'];
$query = mysqli_query($connection,"SELECT * FROM users2 WHERE username LIKE
'%$username%'") or die("Could not search!");
$count = mysqli_num_rows($query);
if($count == 0){
echo "There was no search result!";
}
else{
while($row=mysqli_fetch_array($query)){
echo '<table width = "30%" cellpadding = "2" cellspacing ="2" border = "2px">
<tr>
<td><strong> ID</strong></td>
<td><strong> username</strong> </td>
<td><strong> EC. no</strong> </td>
<td><strong> Division</strong> </td>
<td><strong> ProjectCode</strong> </td>
<td><strong> date of journey</strong> </td>
<td><strong> return date</strong> </td>
<td><strong> From </strong> </td>
<td><strong> To</strong> </td>
<td><button type="submit" name="but" >view form</button></td>
</tr>
<tr>
<td> <input type="text" name="dbid" value='.$row['ID'].' size="4" readonly ></td>
<td>'.$row['username'].'</td>
<td>'.$row['ecno'].'</td>
<td>'.$row['division'].'</td>
<td>'.$row['code'].'</td>
if (isset($_POST['but'])){
$dbid = mysqli_real_escape_string($db, $_POST['dbid']);
$_SESSION['dbid']= $dbid;
header('location: invoice.php');
}
?>
Invoice.php:
<?php
session_start();
$db = mysqli_connect("localhost", "root", "", "logindb1");
if (mysqli_connect_errno())
{
echo "something went wrong with the connection" . mysqli_connect_error();
}
$dbid = $_SESSION['dbid'];
$query = mysqli_query($db,"SELECT * FROM users2 WHERE ID ='$dbid'");
while($row=mysqli_fetch_array($query)){
$ID =$row['ID'];
$username=$row['username'];
$email=$row['email'];
$ecno =$row['ecno'];
$gradepay=$row['gradepay'];
在Homepage.php中我有输出ID作为输入文本框,同样我把它作为输入id。这个方法是否正确?是否有更高效的东西。请帮忙。
答案 0 :(得分:0)
这是因为你没有session_start();在你的第一个档案中。
<?php
session_start();
$connection = mysqli_connect('localhost','root','','logindb1');
当您想要设置或加入会话时,您应该这样做。
还有一个问题是您没有关闭字符串:
echo '<table width = "30%" cellpadding = "2" cellspacing ="2" border = "2px">
<tr>
<td><strong> ID</strong></td>
<td><strong> username</strong> </td>
<td><strong> EC. no</strong> </td>
<td><strong> Division</strong> </td>
<td><strong> ProjectCode</strong> </td>
<td><strong> date of journey</strong> </td>
<td><strong> return date</strong> </td>
<td><strong> From </strong> </td>
<td><strong> To</strong> </td>
<td><button type="submit" name="but" >view form</button></td>
</tr>
<tr>
<td> <input type="text" name="dbid" value='.$row['ID'].' size="4" readonly ></td>
<td>'.$row['username'].'</td>
<td>'.$row['ecno'].'</td>
<td>'.$row['division'].'</td>
<td>'.$row['code'].'</td> </tr></table>';