php - 如何使用php从表中获取输入类型值
问题描述
为什么 $_POST['destination'] 没有值? 请帮忙
如何从输入类型中获取值
<?php while ($row = mysqli_fetch_array($result)){ ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><input type="number" name="day" placeholder="<?php echo $row['day']; ?>"></td>
<td><input type="text" name="destination" placeholder="<?php echo $row['destination']; ?>"></td>
<td><a href="index24.php?delete=<?php echo $row['id']; ?>" class="btn btn-danger"> Edit </a></td>
</tr>
<?php } ?>
//index24.php
$db = mysqli_connect("localhost", "root", "", "testing");
if (isset($_GET['delete'])){
$id = $_GET['delete'];
$destination = $_POST['destination']; //why $_POST['destination'] does not have a value?
$day = $_POST['day'];
$query = "UPDATE tbl_itinerary SET destination = '$destination', day = '$day' WHERE id = '" . $id . "'";
mysqli_query($db,$query);
header('location: index4.php');
}
解决方案
不要在占位符中回显值。你可以这样做:
value="<?php echo $row['day']; ?>
Not like this placeholder="<?php echo $row['day']; ?>"
“占位符旨在向用户显示在字段中输入内容的提示”</p>
编辑
<?php while ($row = mysqli_fetch_array($result)){ ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><input type="number" name="day" value="<?php echo $row['day']; ?>"></td>
<td><input type="text" name="destination" value="<?php echo $row['destination']; ?>"></td>
<td><a href="index24.php?delete=<?php echo $row['id']; ?>" class="btn btn-danger"> Edit </a></td>
</tr>
<?php } ?>
//index24.php
//covertion is important here
$id = intval($_GET['delete']);
$db = mysqli_connect("localhost", "root", "", "testing");
//submit - would be the name of button in your <form> tag.
if (isset($_GET['submit'])){
$destination = $_POST['destination'];
$day = $_POST['day'];
$query = "UPDATE tbl_itinerary SET destination = '$destination', day = '$day' WHERE id = '" . $id . "'";
mysqli_query($db,$query);
header('location: index4.php');
}
Maybe this will help you...
您将 id 的值作为字符串。您需要将其转换为 int。
我建议您使用程序来防止 sql 注入。
推荐阅读
- typescript - Typescript - 仅检查属性是否存在并忽略属性本身的类型检查而不使用任何方法的方法?
- http2 - 为什么不能重用http2流?
- assembly - 在asm中将保护模式(32位)切换到实模式(16位),低电平
- django - 试图将我的模型的外键传递到 URL 以进行动态路由
- java - 编译生成以下错误:“错误:不兼容的类型:推理变量 T 具有不兼容的等式约束 Todo,TodoCouchDB”
- visual-studio-code - 使用 --no-sandbox 运行的电子应用程序会生成警告和错误
- java - 将科学记数法格式的字符串字符转换为标准记数法
- c# - C# 合并 2 个 Json 字符串
- haskell - 应用于 foldr 的 lambda 函数中的 Haskell 相关独立变量
- azure-ad-b2c - B2C 的 givenName 和 surname 声明有什么特别之处吗?无法从 OIDC ClaimsProvider 读取它们