Home > other >  Why can't the input tag have the value of a variable? php
Why can't the input tag have the value of a variable? php

Time:12-25

<?php
$varone = "Hello World";
$str = '<input type="text" width="200px";   name="worksvr" maxlength="999"  value='.$varone.' >';
echo $str;
?>

that's my php code and I want the input to have the value of $varone but for some reason when I run the code it only outputs Hello and does not include World.Any advice would really be helpful thank you in advance

I tried many things including maxlength but that did not help at all.Please any help would be useful thank you.

CodePudding user response:

What you need to do is this

<?php
$varone = "Hello World";
$str = '<input type="text" width="200px";   name="worksvr" maxlength="999"  value="'.$varone.'" >';
echo $str;
?>

Note the quotes around the output of $varone

See: https://onlinephp.io/c/b007f

  • Related