PHP中的更新脚本出错,未定义索引:employee_id

时间:2014-10-11 05:42:32

标签: php html mysql updates

我正在使用PHP脚本从html进行更新。首先,我选择了员工ID,然后在我更新它之后以html格式获取结果,但我每次都会收到此错误:/

这是我的代码:

首先选择员工ID                         

     <?php
   if (isset($_GET['submit'])) {
 $con=mysqli_connect("localhost","root","","hct_db"); 
   $employee_id = mysqli_real_escape_string($con,$_GET['employee_id_db']);

// Check connection
 if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

$result = mysqli_query($con,"SELECT * FROM employee where employee_id = '".$employee_id."'");
 while($row = mysqli_fetch_array($result)) { ?>



                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-6">
                                <form role="form" action="update_employee.php" method="post">
                                     <fieldset disabled>
                                        <div class="form-group">
                                            <label for="disabledSelect">Employee ID</label>
                                            <input class="form-control" id="disabledInput" name="employee_id" type="text" value="<?php echo( htmlspecialchars( $row['employee_id'] ) ); ?>" disabled>
                                        </div></fieldset>
                                    <div class="form-group">
                                        <label>First Name</label>
                                        <input class="form-control"  name="first_name" value="<?php echo( htmlspecialchars( $row['first_name'] ) ); ?>" />
                                    </div>
                                    <div class="form-group">
                                        <label>Last Name</label>
                                        <input class="form-control" name="last_name" value="<?php echo( htmlspecialchars( $row['last_name'] ) ); ?>">
                                    </div>
                                    <div class="form-group">
                                        <label>Username</label>
                                        <input class="form-control" name="username" value="<?php echo( htmlspecialchars( $row['username'] ) ); ?>">
                                    </div>
                                    <div class="form-group">
                                        <label>Password</label>
                                        <input class="form-control" name="password" value="<?php echo( htmlspecialchars( $row['password'] ) ); ?>">
                                    </div>
                                    <div class="form-group">
                                        <label>Date Of Joining</label>
                                        <input type="date" class="form-control" name="date_of_join" value="<?php echo( htmlspecialchars( $row['date_of_join'] ) ); ?>">
                                    </div>
                                    <div class="form-group">
                                        <label>Email ID</label>
                                        <input class="form-control" type="email" name="email_id" value="<?php echo( htmlspecialchars( $row['email_id'] ) ); ?>">
                                    </div>
                                    <div class="form-group">
                                        <label>Address</label>
                                       <input class="form-control" name="address" value="<?php echo( htmlspecialchars( $row['address'] ) ); ?>">                                        </div>
                                    <div class="form-group">
                                        <label>Contact No.</label>
                                        <input class="form-control" name="contact_no" value="<?php echo( htmlspecialchars( $row['contact_no'] ) ); ?>">
                                    </div>


                                    <button type="submit" class="btn btn-default">Submit</button>
                                    <button type="reset" class="btn btn-default">Reset</button>
                                </form>
                            </div>

这是我的update_employee.php脚本

<?php
session_start();
 ob_start();

 $con=mysqli_connect("localhost","root","","hct_db");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// escape variables for security
$first_name = mysqli_real_escape_string($con, $_POST['first_name']);
$last_name = mysqli_real_escape_string($con, $_POST['last_name']);
$address = mysqli_real_escape_string($con, $_POST['address']);
$contact_no = mysqli_real_escape_string($con, $_POST['contact_no']);
$employee_id = mysqli_real_escape_string($con, $_POST['employee_id']);
$username = mysqli_real_escape_string($con, $_POST['username']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$date_of_join = mysqli_real_escape_string($con, $_POST['date_of_join']);
$email_id = mysqli_real_escape_string($con, $_POST['email_id']);

$qq= mysqli_query($con,"UPDATE employee SET first_name='$first_name', last_name='$last_name',   address='$address', contact_no='$contact_no', username='$username', password='$password', date_of_join='$date_of_join', email_id='$email_id'
 WHERE employee_id = '".$employee_id."'");
  if ($qq) {
            echo 'Updated Profile!';
        }else
            echo 'Failed to update your Profile.';

  mysqli_close($con);
  ob_end_flush();
?>

1 个答案:

答案 0 :(得分:0)

您的employee_id输入被标记为已禁用,因此不会发送到表单处理程序。你的意思是把它标记为type =&#34; hidden&#34;而不是禁用它?