如何为数据库中的不同记录/行创建用户生成的链接列表,这些记录/行在单击时填充 html 表单


How to create a user generated list of links for different records/rows in a database that populate an html form when clicked?

嗨,我有这个html表单。 此表单用于收集和存储用户/成员提交的信息。它使用一个数据库,其中有几列2的重要性"user_email"和"invoice_id"。在表单中,"user_email"输入是隐藏的,并且在页面加载时等于登录用户提供的存档电子邮件地址的值。当用户提交多个表单提交时,将在数据库中创建具有相同user_email的多个记录。例如,如果用户 1 提交了 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。

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

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
}
?>