【问题标题】:How to create a user generated list of links for different records/rows in a database that populate an html form when clicked?如何为单击时填充 html 表单的数据库中的不同记录/行创建用户生成的链接列表?
【发布时间】:2015-02-09 17:52:58
【问题描述】:

您好,我有这个 html 表单。此表单用于收集和存储用户/会员提交的信息。它使用具有重要“user_email”和“invoice_id”的多个列 2 的数据库。在表单中,“user_email”输入是隐藏的,并且在页面加载时等于登录用户在文件中提供的电子邮件地址的值。当用户提交多个表单提交时,会在数据库中创建多个具有相同 user_email 的记录。例如,如果 user1 提交了 3 个表单,我的数据库中将有 3 条记录/行,它们的“user_email”列都带有相同的电子邮件。

我试图弄清楚如何创建一个用户生成的链接列表,当点击该链接时,该列表将使用从数据库中获取的数据填充表单。

这是我可以解释我正在尝试实现的场景的最佳方式......

1) 搜索并获取数据库表中“user_email”列值与 sample_form1 输入名称的值匹配的每条记录/行的数据:“user_email”。

<form action="xxx.php" id="sample_form1" name"sample_form1" method="post">


<input type="hidden" id="user_email" name="user_email" value="xxx@email.com">
<input type="text" id="invoice_id" name="invoice_id">
<input type="text" id="other1" name="other1">
<input type="text" id="other2" name="other2">

<input type="submit" value="Submit">


</form>

2) 为每个找到的记录生成链接列表,每个链接对应于找到的不同记录/行,使用“invoice_id”列的值作为生成链接的标签/文本。

EXAMPLE:
Click here to view InvoiceID#001
Click here to view InvoiceID#002
Click here to view InvoiceID#003

3)当点击生成的链接时,使用获取的数据填充 sample_form1。

提前感谢您的时间和帮助。

【问题讨论】:

    标签: javascript php jquery mysql forms


    【解决方案1】:

    1) 搜索并获取数据库表中“user_email”列值与 sample_form1 输入名称的值匹配的每条记录/行的数据:“user_email”。

    $command = "SELECT invoice_id, user_email FROM tableName WHERE user_email = '$user_email'";
    


    2) 为每个找到的记录生成链接列表,每个链接对应于找到的不同记录/行,使用“invoice_id”列的值作为生成链接的标签/文本。
    我没听懂你,但是

    while ($row = mysql_fetch_assoc($result)
    {
        echo '<a href="page.php?id="' . $row['invoice_id'] . '">Click here to see InvoiceID #' . $row['invoice_id'] . '</a>';
    }
    


    3)当点击生成的链接时,使用获取的数据填充 sample_form1。
    你想要什么?只是从 POST 请求中获取数据?

    <?php // xxx.php
    
    // if form is submitted through the POST
    if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST")
    {
        // Get required fields
        $user_email;
        $invoice_id;
        $other1;
        $other2;
    
        if (isset($_POST['user_email']) && $_POST['user_email'] != "")
            $user_email = htmlspecialchars($_POST['user_email']);
    
        if (isset($_POST['invoice_id']) && $_POST['invoice_id'] != "")
            $invoice_id = htmlspecialchars($_POST['invoice_id']);
    
        // Do same with $other1 and $other2
    
        // Now you have to open a connection with DB and put the data
    }
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 1970-01-01
      • 2015-02-15
      • 2015-05-03
      • 2020-06-15
      • 1970-01-01
      • 2017-11-14
      • 2015-02-22
      • 2014-10-08
      相关资源
      最近更新 更多