我有这样的形式进行编辑或更新数据的信息,但是当我点击该按钮用于更新查询$id
值为0如何使用HTML表单POST方法
这里通过从数据库ID号是我的代码:
<form action="edit_crew.php?id=$id" method="POST">
<?php
while(mysqli_stmt_fetch($stmt1)) {
echo "First Name: <input type=\"text\" style=\"border: none; border-color: transparent;\" value=\"$first_name\" name=\"first_name\"><br/>";
echo "Middle Name: <input type=\"text\" style=\"border: none; border-color: transparent;\" value=\"$middle_name\"><br/>";
echo "Last Name: <input type=\"text\" style=\"border: none; border-color: transparent;\" value=\"$last_name\"><br/>";
echo "Age: <input type=\"text\" style=\"border: none; border-color: transparent;\" value=\"$age\"><br/>";
echo "<button type=\"button\" class=\"btn btn-success\" onclick=\"document.location = 'edit_crew.php?id=$id'; \">Continue</button></center>";
}
?>
</form>
这里是我的UPDATE
查询代码:
<?php
include '../session.php';
require_once 'config.php';
include 'config.php';
$query_update = "UPDATE `crew_info` SET `first_name` = ?, `middle_name` = ?, `last_name` = ?, `age` = ?, `month` = ?, `day` = ?, `year` = ?, `birth_place` = ?, `gender` = ?, `martial_status` = ?, `religion` = ?, `nationality` = ?, `email_address` = ?, `address_1` = ?, `address_2` = ?, `course` = ?, `school_graduated` = ?, `remarks` = ? WHERE `id` = ?";
$stmt2 = mysqli_prepare($conn, $query_update);
$first_name = $_POST['first_name'];
mysqli_stmt_bind_param($stmt2, 'sssisiisssssssssssi', $first_name, $middle_name, $last_name, $age, $month, $day, $year, $birth_place, $gender, $martial_status, $religion, $nationality, $email_address, $address_1, $address_2, $course, $school_graduated, $remarks, $_GET['id']);
mysqli_stmt_execute($stmt2);
?>
我想查询是正确的,唯一的问题是id
是空
下面是我如何获得我使用的mysqli的$id
准备
<?php
include '../session.php';
require_once 'config.php';
include 'header.php';
$query1 = "SELECT * FROM `crew_info` WHERE `id` = ?";
$stmt1 = mysqli_prepare($conn, $query1);
mysqli_stmt_bind_param($stmt1, 's', $_GET['id']);
mysqli_stmt_execute($stmt1);
mysqli_stmt_bind_result($stmt1, $id, $first_name, $middle_name, $last_name, $age, $month, $day, $year, $birth_place, $gender, $martial_status, $religion, $nationality, $email_address, $address_1, $address_2, $course, $school_graduated, $remarks, $date_added, $crew_status, $image_name, $passport);
?>
Try'
still'id' is empty – Adi
你是如何得到'$ id'的?显示该代码(在原始问题中)。 – Tigger