0
好的,我正在使用PHP腳本從html進行更新。首先我選擇僱員ID,然後在之後的HTML表單我更新它取結果,但每次我收到此錯誤:/在PHP更新腳本中出現錯誤,未定義索引:employee_id
這裏是我的代碼:
首先選擇員工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();
?>
好吧,讓我試試這個 – AakkiRock 2014-10-11 05:51:30
是的,它的隱藏類型很好,..非常感謝。你節省了我很多時間:) – AakkiRock 2014-10-11 05:54:35
真棒,很高興我能幫助! – Yavor 2014-10-11 06:04:32