简体   繁体   English

将来自不同文件的php索引传递到html表单输入字段

[英]Passing a php index from a different file into an html form input field

I'm unable to correctly have my variable show up when I call its value in the input field. 在输入字段中调用变量的值时,无法正确显示变量。 I did not include the other input fields from the form because they all work. 我没有包括表单中的其他输入字段,因为它们都起作用。 I just need to get the users nickname to insert into the nickname field when the pages loads. 我只需要获取用户昵称即可在页面加载时插入昵称字段。 I've seen very many old takes on this that don't work anymore and not cure how to proceed currently. 我已经看到了很多旧的方法,这些方法不再起作用,并且无法治愈当前的方法。

I've tried passing the $nickname session, using $_POST, $_GET, but am still unable to get it working. 我尝试使用$ _POST,$ _ GET传递$ nickname会话,但是仍然无法使其正常工作。

coinsubmission.html coinubmission.html

<form autocomplete="off" action="AdminCoinSub_Code.php" method="POST">
    <input type="text" name="Nickname" id="Nickname" placeholder="Nickname">
</form>

AdminCoinSub_Code.php 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;
}

When the coinsubmission page loads the Nickname for the user should be automatically inserted into the "Nickname" field. 硬币共享页面加载后,应将用户的昵称自动插入“昵称”字段。 I've include db structure below. 我在下面包括了数据库结构。

coins 硬币

硬币

adminlogin 管理员登录

管理员登录

Your prepare call is invalid. 您的准备呼叫无效。 You should use parameters and then bind your POST data. 您应该使用参数,然后绑定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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM