我有一个html表格,我需要在其中安全安全地接受用户输入以更新表格项。有指导吗? (我知道我在下面写的是不正确的)
例如,如果他们想更新自己的详细信息,例如姓氏:
<div class="grid-2">
<p><b>UPDATE MY DETAILS</b></p>
<form action ="includes/update.inc.php" method ="post">
<label>S.Name</label>
<input name="update-surname" type="text" placeholder="Enter new surname...">
<label>Address</label>
<input name="update-houseno" type="text" placeholder="Enter house no' or name...">
<input name="update-ln1" type="text" placeholder="1st Line of Address...">
<input name="update-town" type="text" placeholder="Town...">
<input name="update-county" type="text" placeholder="County...">
<input name="update-postcode" type="text" placeholder="Postcode...">
<label>Contact Number</label>
<input name="update-number" type="text" placeholder="Contact Number...">
<label>Email</label>
<input name="update-email" type="text" placeholder="Email...">
<input type="submit" name="update-details" value="Update">
</form>
</div>
更新我已经在上面的页面中添加了代码,并根据要求对表单进行了操作。下面的代码是我对该操作所导致的页面的开始:
<?php
// Here we check whether the user got to this page by clicking the proper button.
if (isset($_POST['update-details'])) {
require 'dbh.inc.php';
// We grab all the data which we passed from the update form so we can use it later.
$surname = $_POST['update-surname'];
$houseno = $_POST['update-houseno'];
$ln1 = $_POST['update-ln1'];
$town = $_POST['update-town'];
$county = $_POST['update-county'];
$postcode = $_POST['update-postcode'];
$number = $_POST['update-number'];
$email = $_POST['update-email'];
// We validate email is correct if email has been updated.
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../after-login.php?error=invalidmail&uid=");
exit();
}
}
?>
答案 0 :(得分:1)
因此,您需要对表单进行操作-即一个脚本,将其指向处理表单(可以是相同的脚本)。理想情况下,您还希望将方法设置为post,以使数据在url中不可见,然后您需要清理数据,连接到db并进行查询。
这应该可以帮助您获得正确的想法