我目前有一个个人资料页面,可将员工信息输出到个人资料页面。我们的想法是能够进入该个人资料页面,编辑显示的信息,单击更新按钮并更新我本地数据库中的记录。目前,我刚刚删除了整行。
<!-- OUTPUTS FORM DATA TO USER (TRIALING WITH EMPLOYEE WITH ID = 49) -->
<?php
$query2 = "SELECT * FROM users WHERE id = '49'";
$result2 = mysqli_query($db, $query2);
$row2 = mysqli_fetch_array($result2);
?>
<form class="profile-form" action="update.php" method="post">
<label class="profile-label" for="id">Employee ID:</label>
<input class="profile-input" type="text" name="id" value="<?php echo $row2['id']; ?>"><br><br>
<label class="profile-label" for="firstname">First name:</label>
<input class="profile-input" type="text" name="firstname" value="<?php echo $row2['firstname']; ?>"><br><br>
<label class="profile-label" for="lastname">Last name:</label>
<input class="profile-input" type="text" name="lastname" value="<?php echo $row2['lastname']; ?>"><br><br>
<label class="profile-label" for="contact">Contact Number:</label>
<input class="profile-input" type="text" name="contact" value="<?php echo $row2['contact']; ?>"><br><br>
<label class="profile-label" for="address">Address:</label>
<input class="profile-input" type="text" name="address" value="<?php echo $row2['address']; ?>"><br><br>
<label class="profile-label" for="pc">Post Code:</label>
<input class="profile-input" type="text" name="pc" value="<?php echo $row2['pc']; ?>"><br><br>
<label class="profile-label" for="email">Email Address:</label>
<input class="profile-input" type="text" name="email" value="<?php echo $row2['email']; ?>"><br><br>
<label class="profile-label" for="branch">Branch:</label>
<input class="profile-input" type="text" name="branch" value="<?php echo $row2['branch']; ?>"><br><br>
<label class="profile-label" for="role">Role:</label>
<input class="profile-input" type="text" name="role" value="<?php echo $row2['role']; ?>"><br><br>
<label class="profile-label" for="ext">Extension Number:</label>
<input class="profile-input" type="text" name="ext" value="<?php echo $row2['ext']; ?>"><br><br>
<label class="profile-label" for="reg">Registration Number:</label>
<input class="profile-input" type="text" name="reg" value="<?php echo $row2['reg']; ?>"><br><br>
<label class="profile-label" for="NI">National Insurance Number:</label>
<input class="profile-input" type="text" name="NI" value="<?php echo $row2['NI']; ?>"><br><br><p>
<input class="profile-button" type="submit" value="Update">
</form>
</div>
//这是update.php
<?php
$firstname = "";
$lastname = "";
$contact = "";
$address = "";
$pc = "";
$email = "";
$branch = "";
$role = "";
$ext = "";
$reg = "";
$NI = "";
$holStart = "";
$holEnd = "";
$errors = array();
// connect to the database
$db = mysqli_connect('localhost', 'root', '', 'registration');
$sql = "UPDATE userscopy SET firstname = '$firstname' WHERE id='49'";
if ($db->query($sql) === TRUE) {
echo "Records updated";
}
else {
echo "Error: ".$sql."<br>".$db->error;
}
?>
请注意,我已连接到数据库并且正在获取输出。我唯一的问题是我的 UPDATE sql 正在删除该行。(或者在这种情况下只是名字)。我哪里错了?
正如在对您的问题的评论中提到的,您的 UPDATE 语句正在将名字字段更新为长度为零的字符串 ("")。由于您使用 POST 方法从客户端调用服务器,因此从 post 读取值以更新(以您的形式):
$firstname=$_POST['firstname']);
等等所有值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句