php - 将不同文件中的 php 索引传递到 html 表单输入字段
问题描述
当我在输入字段中调用它的值时,我无法正确显示我的变量。我没有包括表单中的其他输入字段,因为它们都有效。我只需要在页面加载时将用户昵称插入昵称字段。我已经看到了很多旧的方法,这些方法不再起作用,也无法治愈目前如何进行。
我尝试使用 $_POST、$_GET 传递 $nickname 会话,但仍然无法使其正常工作。
硬币提交.html
<form autocomplete="off" action="AdminCoinSub_Code.php" method="POST">
<input type="text" name="Nickname" id="Nickname" placeholder="Nickname">
</form>
AdminCoinSub_Code.php
<?php
if (isset($_POST['Next'])) {
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "administrator_logins";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO coins (Store, Position,
Nickame, ContactNumber, MachineCount, CutOffDate, Coins, location)
VALUES
('$_POST[Store]','$_POST[Position]',
'$_POST[Nickame]','$_POST[ContactNumber]','$_POST[MachineCount]','$_POST[CutOffDate]',
'$_POST[Coins]','$_POST[location]')");
$stmt->bindParam(':Store', $Store);
$stmt->bindParam(':Position', $Position);
$stmt->bindParam(':Nickname', $Nickname);
$stmt->bindParam(':ContactNumber', $ContactNumber);
$stmt->bindParam(':MachineCount', $MachineCount);
$stmt->bindParam(':CutOffDate', $CutOffDate);
$stmt->bindParam(':Coins', $Coins);
$stmt->bindParam(':location', $location);
$stmt->execute();
echo "Success: Go back";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
}
当共同提交页面加载用户的昵称时,应自动将其插入“昵称”字段。我在下面包含了数据库结构。
硬币
管理员登录
解决方案
您的准备调用无效。您应该使用参数,然后绑定您的 POST 数据。
$stmt = $conn->prepare("INSERT INTO coins (Store, Position,
Nickame, ContactNumber, MachineCount, CutOffDate, Coins, location)
VALUES (:Store,:Position, :Nickname,:ContactNumber,:MachineCount,:CutOffDate, :Coins,:location)");
$stmt->bindParam(':Store', $_POST['Store']);
$stmt->bindParam(':Position', $_POST['Position']);
$stmt->bindParam(':Nickname', $_POST['Nickname']);
$stmt->bindParam(':ContactNumber', $_POST['ContactNumber']);
$stmt->bindParam(':MachineCount', $_POST['MachineCount']);
$stmt->bindParam(':CutOffDate', $_POST['CutOffDate']);
$stmt->bindParam(':Coins', $_POST['Coins']);
$stmt->bindParam(':location', $_POST['location']);
$stmt->execute();
推荐阅读
- svg - how to do svg transform in percentage
- kubernetes - 如何使用ansible验证yml创建的所有pvc?
- jquery - 从 CDN 加载 WordPress 5.2 jQuery 脚本
- javascript - D3 可以读取“Geojson”文件吗?
- monitoring - Prometheus:是否可以在配置文件中为 job_name>static_configs>targets 编写正则表达式
- vba - 是否有允许我将一天中的小时数设置为少于 24 小时的 VBA 功能?
- kubernetes - 如何将 kubectl 连接到 Google Cloud 中的集群?
- python - 比较两个整数时 if 语句不起作用
- ios - 导入数据后如何重新加载 UITableView?
- ios - CAShapeLayer() 绘制奇怪的线/路径