html.编辑数据回显,从HTML表格编辑/更新MySQL数据库值
我有一個表單,目前提交值到MySQL數據庫。在每次提交完成后,剛剛插入到mysql數據庫的數據將在表單下回顯。該表格具有動態輸入字段。我知道想要添加編輯以前插入的值的可能性。我放置了一個編輯按鈕,將用戶重定向到一個personel_edit.php頁面,希望將所有輸??入字段填充到??。在代碼中,您將看到如何進行初始插入,然后在執行選擇后顯示插入的信息。但我不知道如何根據??填充此動態字段或將數據傳遞到編輯頁面? Example從HTML表格編輯/更新MySQL數據庫值
提交后 - 插入/顯示
if(isset($_POST['submit'])){
$name = $_POST['name'];
$acad_id = $_POST['acad_id'];
$courses_offered=$_POST['courses_offered'];
$query_init = "INSERT INTO academy (name, academy_id) VALUES (:name, :acad_id);";
$query_prep = $db_con->prepare($query_init);
$insert_result = $query_prep->execute(array(
"name" => $name,
"acad_id" => $acad_id
));
$s = 1;
while(isset($_POST['person_fname_' . $s]))
{
$contact_role = isset($_POST['person_contact_' . $s]) ? 1 : 0;
$instructor_role = isset($_POST['person_instructor_' . $s]) ? 1 : 0;
$person_fname = $_POST['person_fname_' . $s];
$person_lname = $_POST['person_lname_' . $s];
$person_email = $_POST['person_email_' . $s];
$person_phone = $_POST['person_phone_' . $s];
$person_fax = $_POST['person_fax_' . $s];
$query_init2 = "INSERT INTO person (academy_id, contact_role, instructor_role, first_name, last_name, person_email, person_phone, person_fax) VALUES (:acad_id,:contact_role,:instructor_role,:person_fname,:person_lname,:person_email,:person_phone,:person_fax);";
$query_prep2 = $db_con->prepare($query_init2);
$insert_result2 = $query_prep2->execute(array(
"acad_id" => $acad_id,
"contact_role" => $contact_role,
"instructor_role" => $instructor_role,
"person_fname" => $person_fname,
"person_lname" => $person_lname,
"person_email" => $person_email,
"person_phone" => $person_phone,
"person_fax" => $person_fax
));
$s++;
}
$db_select = $db_con->prepare("
SELECT a.name,
a.academy_id,
p.contact_role,
p.instructor_role,
p.first_name,
p.last_name,
p.person_email,
p.person_phone,
p.person_fax
FROM academy a
INNER JOIN person p ON a.academy_id = p.academy_id
WHERE a.academy_id = :acad_id
");
if (!$db_select) return false;
if (!$db_select->execute(array(':acad_id' => $acad_id))) return false;
$results = $db_select->fetchAll(\PDO::FETCH_ASSOC);
if (empty($results)) return false;
$final_result = '';
$first = true;
foreach ($results as $value){
if($first){
$first = false;
$final_result .= "Academy Name: ".$value['name']." ID: ".$value['academy_id']."";
}
$final_result .= "---------------------PERSONEL-----------------------";
$final_result .= "First Name: ".$value['first_name']."Last Name: ".$value['last_name']."Email: ".$value['person_email']."";
$final_result .= "This person has the role of an instructor: ".$value['instructor_role']."This person has the role of a contact: ".$value['contact_role']."";
$final_result .= "Phone: ".$value['person_phone']."Fax: ".$value['person_fax']."";
}
$final_result .= 'Edit';
}
?>
HTML表單
Name:
Academy
How many courses offered?
---Select---
1
2
Personel Information:
Concact
Instructor
總結
以上是生活随笔為你收集整理的html.编辑数据回显,从HTML表格编辑/更新MySQL数据库值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国人事考试网html制作,中国人事考试
- 下一篇: .net core 生成html,ASP