0

so i have code php like this:

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

and i want to pass the $fname from the php file to an html file

in my html file i want to print on the screen "dor"

how to do it?

but when i run it i get this error:

Undefined index: fname

what should i do? tnx for helpers :)

Dor Cohen
  • 117
  • 1
  • 4
  • 10

3 Answers3

0

you can include a PHP file -

index.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" />

variable.php:

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

myphpfile.php:

<?Php
   print $_POST['fname']; // will print the value of fname after submitting the form
?>
Jentel
  • 148
  • 2
  • 17
0

You can actually use this.

Name: <input type="text" name="fname" value=<?= $fname ?> />
rccoros
  • 590
  • 9
  • 19
0

It is not possible to pass data from PHP to a HTML file.

If your question is to display a php variable value with html markup, you should create a php file and do something like this:

<?php
$fname = "test";
?>
<div><?php echo $fname; ?></div>
randomizer
  • 1,619
  • 3
  • 15
  • 31