表格更新-不起作用

脚踝

全部,

我从过时的迁移mysql_querymysqli该过程中,在表单更新更改方面遇到了一些问题。具体来说,似乎$ud_id要获取的变量id不起作用。

查询被写入左外部联接链接表,empinfo并且headcount这两个都包含链接主ID。

这是edit.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 -

<!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>

update.php的第52行,您会注意到我使用echo$ud_ID$ud_EmployeeName-这是向我展示变量显示的内容。$ud_EmployeeName出现,$ud_ID没有。

我也尝试使用

$ud_ID = $_POST["ID"];

我没有结果。

另外,在edit.php上,我尝试了:

echo '<input type="hidden" name="ud_ID" value='. $row["id"] .'><br />';

我收到错误:

Notice: Undefined index: ID in update.php on line 27

当我单击submit按钮时,我收到一条消息,记录已更新,但刷新后,该记录具有相同的数据。

马姆塔

嗨,使用name属性获取价值

$ud_ID = $_POST['ud_ID'];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章