所有
我正在从过时的mysql_query
迁移到mysqli
,在此过程中,我遇到了表单更新更改的一些问题。具体来说,好像获得$ud_id
的{{1}}变量不起作用。
查询将写入左外连接链接表id
和empinfo
,其中包含这两个链接主ID。
以下是 edit.php 页面按预期工作和加载:
headcount
这是 update.php -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<div class="header">
<?php include 'header.php';?>
</div>
<center>
<?php
// db connection
include_once('../connection.php');
// id pull from url
$ID = (int)$_GET['id'];
// get results from database
$query = "SELECT headcount.*, empinfo.*
FROM headcount
LEFT OUTER JOIN empinfo
ON headcount.id = empinfo.id
WHERE headcount.id = '$ID'";
$response = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($response))
{
echo "<form action='update.php' method='post'>";
echo '<div style="width:40%;padding:0 10pt 0 0;float:middle;">';
if ($row['isActive'] === '1')
echo '<input type="checkbox" name="ud_isActive" value="1" checked>Active<br />';
else
echo '<input type="checkbox" name="ud_isActive" value="0">Active<br />';
echo '<input type="hidden" name="ud_ID" value="<?=$ID;?>">';
echo "ID #: <input type='text' name='ud_hwid' value=". $row['id'] ." disabled readonly><br />";
echo 'Name: <input type="text" name="ud_EmployeeName" value="'. $row["EmployeeName"] .'"><br />';
echo '<br />';
echo '<a href="mailto:' . $row["Email"] .'">Email</a>: <input type="text" name="ud_Email" value="'. $row["Email"] .'"><br>';
echo '<br />';
echo 'DOB: <input type="text" name="ud_DOB" value='. $row["DOB"] .'><br />';
echo 'Age: <input type="text" name="ud_Age" value='. $row["Age"] .'><br />';
if ($row['isUnderage'] === '1')
echo '<input type="checkbox" name="isUnderage" value="1" checked>Underage<br />';
else
echo '<input type="checkbox" name="isUnderage" value="0">Underage<br />';
echo '</div>';
echo '<div style="width:40%;padding:0 10pt 0 0;float:middle;">';
echo '<br />';
echo 'Address: <input type="text" name="ud_StreetAddress" value="'. $row["StreetAddress"] .'"><br />';
echo 'City: <input type="text" name="ud_City" value="'. $row["City"] .'"><br />';
echo 'Zip Code: <input type="text" name="ud_ZipCode" value="'. $row["ZipCode"] .'"><br />';
echo '<br />';
echo 'Home Phone: <input type="text" name="ud_HomePhone" value="'. $row["HomePhone"] .'"><br />';
echo 'Wireless: <input type="text" name="ud_Wireless" value="'. $row["Wireless"] .'"><br />';
echo '<br />';
echo 'Home Department: <input type="text" name="ud_HomeDept" value="'. $row["HomeDept"] .'"><br />';
echo 'Department Manager: <input type="text" name="ud_Manager" value="'. $row["Manager"] .'"><br />';
echo '</div>';
echo '<br />';
echo 'Live Orientation:<input type="date" name="LODate" value=""><br />';
echo '<br />';
echo 'Online Training: <input type="date" name="OTTraining" value=""><br />';
}
?>
<br />
<input type="Submit">
</form> <br />
<a href="javascript:history.back()">Go Back</a>
<br />
</body>
</html>
在 update.php 的第52行,你会注意到我使用echo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css">
#wrap {
width:600px;
margin:0 auto;
}
#left_col {
float:left;
width:300px;
}
#right_col {
float:right;
width:300px;
}
</style>
<div class="header">
<?php include 'header.php';?>
</div>
<center>
<?php
$ud_ID = $_REQUEST["ID"];
$ud_EmployeeName = $_POST["ud_EmployeeName"];
$ud_Email = $_POST["ud_Email"];
$ud_DOB = $_POST["ud_DOB"];
$ud_Age = $_POST["ud_Age"];
$ud_StreetAddress = $_POST["ud_StreetAddress"];
$ud_City = $_POST["ud_City"];
$ud_ZipCode = $_POST["ud_ZipCode"];
$ud_HomePhone = $_POST["ud_HomePhone"];
$ud_Wireless = $_POST["ud_Wireless"];
$ud_HomeDept = $_POST["ud_HomeDept"];
$ud_Manager = $_POST["ud_Manager"];
// db connection
include_once('../connection.php');
$query = "UPDATE headcount SET
EmployeeName = '$ud_EmployeeName', Email = '$ud_Email',
DOB = '$ud_DOB', Age = '$ud_Age', StreetAddress = '$ud_StreetAddress',
City = '$ud_City', ZipCode = '$ud_ZipCode', HomePhone = '$ud_HomePhone',
Wireless = '$ud_Wireless', HomeDept = '$ud_HomeDept', Manager = '$ud_Manager'
WHERE ID = '$ud_ID'";
$response = mysqli_query($dbc, $query);
echo $ud_ID;
echo $ud_EmployeeName;
if ($response)
echo '<p>Record Updated<p> <br /> <a href="javascript:history.back()">Go Back</a>';
else
echo "Problem updating record. MySQL Error: " . mysql_error();
?>
</body>
</html>
和$ud_ID
- 这是为了告诉我变量显示的内容。出现$ud_EmployeeName
而$ud_EmployeeName
则没有。
我也尝试过使用
$ud_ID
我没有结果。
此外,在 edit.php 上,我尝试过:
$ud_ID = $_POST["ID"];
我收到错误:
echo '<input type="hidden" name="ud_ID" value='. $row["id"] .'><br />';
当我单击Notice: Undefined index: ID in update.php on line 27
按钮时,我收到记录已更新的消息,但在刷新时,记录具有相同的数据。
答案 0 :(得分:1)
您可以使用name属性获取值
$ud_ID = $_POST['ud_ID'];