edit_accounts.php
<?php $get_id = $_GET['id']; ?>
<?php// $get_id = isset($_POST['id']) ? $_POST['id'] : ''; ?>
<div class="container">
<div class="margin-top">
<div class="row">
<div class="span12">
<?php
$query=mysqli_query($dbcon,"select * from users_tbl where id ='$get_id'")or die(mysqli_error());
$row=mysqli_fetch_array($query);
$id=$row['id'];
?>
<div class="alert alert-info"><i class="icon-pencil"></i> Edit Member</div>
<p><a class="btn btn-info" href="users.php"><i class="icon-arrow-left icon-large"></i> Back</a></p>
<div class="addstudent">
<div class="details">Please Enter Details Below</div>
<form class="form-horizontal" method="POST" action="update_accounts.php" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label" for="inputEmail">User_ID:</label>
<div class="controls">
<input type="text" id="inputEmail" value="<?php echo $row['code'];?>" name="code" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Username:</label>
<div class="controls">
<input type="text" id="inputEmail" name="username" maxlength="30" value="<?php echo $row['username'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Firstname:</label>
<div class="controls">
<input type="text" id="inputPassword" name="firstname" maxlength="30" value="<?php echo $row['firstname'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Middlename:</label>
<div class="controls">
<input type="text" id="inputPassword" name="middlename" maxlength="30" value="<?php echo $row['middlename'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Lastname:</label>
<div class="controls">
<input type="text" id="inputEmail" name="lastname" value="<?php echo $row['lastname'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email:</label>
<div class="controls">
<input type="email" id="inputEmail" name="email" value="<?php echo $row['email'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Address:</label>
<div class="controls">
<input type="text" id="inputEmail" name="address" value="<?php echo $row['address'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Contact No:</label>
<div class="controls">
<input type="text" id="inputEmail" name="contact_number" maxlength="11" value="<?php echo $row['contact_number'];?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Position:</label>
<div class="controls">
<input type="text" id="inputEmail" name="position" value="<?php echo $row['position'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">User Type:</label>
<div class="controls">
<input type="text" id="inputEmail" name="type_id" value="<?php echo $row['type_id'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">BirthDate:</label>
<div class="controls">
<input type="date" id="inputEmail" name="birthdate" value="<?php echo $row['birthdate'];?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Date Started:</label>
<div class="controls">
<input type="date" id="inputEmail" name="date_started" value="<?php echo $row['date_started'];?>">
</div>
</div>
<div class="control-group">
<div class="controls">
<button name="submit" type="submit" class="btn btn-success"><i class="icon-save icon-large"></i> Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
if (isset($_POST['submit'])){
$usercode=$_POST['code'];
$username=$_POST['username'];
$firstname=$_POST['firstname'];
$middlename=$_POST['middlename'];
$lastname=$_POST['lastname'];
$type_id=$_POST['type_id'];
$birthdate=$_POST['birthdate'];
$address = $_POST['address'];
$email=$_POST['email'];
$password="qwerty";
$contact_number=$_POST['contact_number'];
$position=$_POST['position'];
$date_started=$_POST=['date_started'];
mysqli_query($dbcon,"UPDATE users_tbl set
code='$usercode',firstname='$firstname',lastname='$lastname',middlename = '$middlename',
lastname = '$lastname',type_id = '$type_id',birthdate = '$birthdate',address = '$address',email = '$email',password = '$password',
contact_number = '$contact_number',position = '$position',date_started = '$date_started' where id='$id'")or die(mysqli_error());
?>
<script>alert('Update Status Successful!');
window.location='accounts.php';</script>;
<?php
}
?>
accounts.php
<thead>
<tr>
<th>User ID:</th>
<th>Username</th>
<th>Firstname</th>
<th>Middlename</th>
<th>Lastname</th>
<th>Email</th>
<th>Address</th>
<th>Contact No.</th>
<th>Position</th>
<th>User Type:</th>
<th>Birthdate:</th>
<th>Date Started</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $user_query=mysqli_query($dbcon,"select * from users_tbl")or die(mysqli_error());
while($row=mysqli_fetch_array($user_query)){
$id=$row['id']; ?>
<tr class="del<?php echo $id ?>">
<td><?php echo $row['code']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['middlename']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['contact_number']; ?></td>
<td><?php echo $row['position']; ?></td>
<td><?php echo $row['type_id']; ?></td>
<td><?php echo $row['birthdate']; ?></td>
<td><?php echo $row['date_started']; ?></td>
<td class="action">
<a rel="tooltip" title="Delete" id="<?php echo $id; ?>" href="#delete_book<?php echo $id; ?>" data-toggle="modal" class="btn btn-danger"><i class="icon-trash icon-large"></i></a>
<?php include('delete_book_modal.php'); ?>
<a rel="tooltip" title="Edit" id="<?php echo $id; ?>" href="edit_accounts.php<?php echo '?id='.$id; ?>" class="btn btn-success"><i class="icon-pencil icon-large"></i></a>
</tr>
<?php } ?>
</tbody>
</table>
当我按下编辑时,所有信息都在那里,点击更新后,错误将显示(如图所示)它已经获得了ID,因为如果没有,它将不会显示信息。并且它不保存我的更新,我更改了信息,但点击按钮后信息仍然相同。
答案 0 :(得分:0)
试试这个, 替换:
$query=mysqli_query($dbcon,"select * from users_tbl where id
='$get_id'")or die(mysqli_error());
到
$query=mysqli_query($dbcon,"select * from users_tbl where id
=$get_id")or die(mysqli_error());
删除单引号。它没有取代它的价值。
如果这对你有用,请告诉我。
答案 1 :(得分:0)
你应该检查,是否返回结果或没有。 如果您的数据库中没有正确的ID,则可能出现此错误。
<section id="kalender" class="kalender-section content-section text-center">
<div class="container">
<div class="row">
<div class="col-lg-4 col-lg-push-8 mx-auto">
B
</div>
<div class="col-lg-8 col-lg-push-4 mx-auto">
A
</div>
</div>
</div>
</section>
PS:花时间学习准备好的陈述。并且不要使用将参数传递给SQL查询的方式。在这种情况下,执行SQL注入非常容易。