簡體   English   中英

如何在單擊時填充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表單。 該表格用於收集和存儲用戶/會員提交的信息。 它使用具有重要性為“ 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。

感謝您的寶貴時間和提前的幫助。

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
}

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM