【问题标题】:how to take the id in the filter table as input and get the data as output如何将过滤表中的id作为输入并获取数据作为输出
【发布时间】:2017-11-12 13:06:38
【问题描述】:

我一直在这个网站上工作,该网站打印提交表格的用户的表格。我使用“查看表单”按钮通过 FPDF 生成表单的 PDF。 我的问题是我无法打印我点击的表格。而是生成了最后一个提交的表单。 这是代码: 主页.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');


 }
 ?>

发票.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。这种方法正确吗?有没有更有效的东西。请帮忙。

【问题讨论】:

    标签: php html mysql fpdf


    【解决方案1】:

    那是因为你没有 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>';
    

    【讨论】:

    • 嘿。我这样做了,但我仍然无法获得我点击的表单详细信息,而不是最后提交的表单。
    • 你确定 $_SESSION['dbid'] 和 $row 有价值吗?你可以检查 echo $_SESSION['dbid'];和 print_r($row);
    猜你喜欢
    • 1970-01-01
    • 2022-12-31
    • 2021-12-23
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多