1

I want to set the value of an input text field with php, but it does not seem to work. There are many similar Questions where the answer was something like this:

<?php $value = "Show This!" ?>
<form>
<input type="text" name="testname" value="<?php echo $value;?>" >
</form>

But this will print the whole <?php... stuff in the text field like this.

For clarification:. I am expecting to see this.

What am I doing wrong?

Note: I also tried several variants with/without string symbols, also the shorthand variant <input type="text" value="<?=$value?>"> and even something without a php variable:

<form>
<input type="text" name="testname" value="<?php echo 'Show this please';?>" >
</form>
  • 3
    Is your PHP server running? Does the file have the .php extension? – Wais Kamal Jun 18 '21 at 08:46
  • 2
    Your code is totaly not the probleme. Check the server. Check the file extension. Create a index.php and just write ` – Rudy David Jun 18 '21 at 09:08
  • Does this answer your question? [PHP code is not being executed code shows in browser](https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-code-shows-in-browser) – rpm192 Jun 18 '21 at 09:08
  • @WaisKamal I am using the code in a Wordpress site which probably is an .html file, so that is indeed the problem. What I initially inteded to do is [this](https://stackoverflow.com/a/55394275) Guess I will have to try out some javascript solutions then... – Blue-Banana Jun 18 '21 at 09:50
  • Yes it can be done with javascript. – Wais Kamal Jun 18 '21 at 17:39

1 Answers1

0

your code looks correct, you just need to run it as PHP instead of HTML

Martin Meli
  • 452
  • 5
  • 18