0

所以我有这样的代码php:

$fname="dor";
$fname=$_POST["fname"];

我想将 $fname 从 php 文件传递​​给 html 文件

在我的 html 文件中,我想在屏幕上打印“dor”

怎么做?

但是当我运行它时,我得到了这个错误:

Undefined index: fname

我应该怎么办?tnx 帮手 :)

4

3 回答 3

0

您可以包含一个 PHP 文件 -

索引.php:

<?Php
 include 'variable.php';
 if(!$fname) // if $fname does not exists then create it with no value
   $fname = null;
?>
<form action="myphpfile.php" method="POST">
    Name: <input type="text" name="fname" value="$fname" />
    <input type="submit" />

变量.php:

<?Php
  $fname = 'Dor';
?>

myphpfile.php:

<?Php
   print $_POST['fname']; // will print the value of fname after submitting the form
?>
于 2014-01-15T08:52:51.423 回答
0

您实际上可以使用它。

Name: <input type="text" name="fname" value=<?= $fname ?> />
于 2014-01-15T09:00:23.677 回答
0

无法将数据从 PHP 传递到 HTML 文件。

如果您的问题是使用 html 标记显示 php 变量值,您应该创建一个 php 文件并执行以下操作:

<?php
$fname = "test";
?>
<div><?php echo $fname; ?></div>
于 2014-01-15T09:24:21.270 回答