Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以html格式发送具有给定值的php变量_Php_Html_Variables - Fatal编程技术网

如何以html格式发送具有给定值的php变量

如何以html格式发送具有给定值的php变量,php,html,variables,Php,Html,Variables,我的PHP代码有问题。我正在尝试将变量发送到另一个页面。我知道如何处理其他变量,因为我在表单中给出了它们的值。但是,如果我有一个变量,我想发送一个给定的值(我以前给出的值),该怎么办 在本例中,我要发送的变量称为$Dir,它包含一个文件的路径,其中包含一些有关事件的信息。我想将该路径发送到下一页,以便它可以打开它。代码如下: <html> <body> <h1>Select one option...</

我的PHP代码有问题。我正在尝试将变量发送到另一个页面。我知道如何处理其他变量,因为我在表单中给出了它们的值。但是,如果我有一个变量,我想发送一个给定的值(我以前给出的值),该怎么办

在本例中,我要发送的变量称为
$Dir
,它包含一个文件的路径,其中包含一些有关事件的信息。我想将该路径发送到下一页,以便它可以打开它。代码如下:

    <html>
         <body>
            <h1>Select one option...</h1> 
         </body>
        <form action="button2.php" method="post" target="page">
        <input type="submit" name="Add" value="Participate on the event"> 
        <input type="submit" name="Mod" value="Modify my information"> 
        <input type="submit" name="Erase" value="Erase my confirmation"> 
        <input type="submit" name="Info" value="See the event information"> 
            <input type="hidden" name="Dir" value=$Dir"> 
        </form>
        <iframe name="page" src="button2.php"> //llamada al botton.php
        </iframe>
    </html>


选择一个选项。。。

问题

$filePathID = 1;

<input type="hidden" name="Dir" value=<?php echo $filePathID; ?>"> 
您正在尝试将PHP变量解析为HTML中的文件路径字符串

解决方案

您可以使用
echo
输出字符串

$filePathID = 1;

<input type="hidden" name="Dir" value=<?php echo $filePathID; ?>"> 
if ($_POST['Dir'] == 1) {
    $filePath = "C:/user/file.txt"
}    else   {
    $filePath = "C:/user/otherFile.txt"
}

// Do something with the... $filePath;