1

What i wanna do is having an input form with a value from a php variable,here is my input form code:

echo "<input type=\"text\" class=\"form-control\" placeholder=\"Username\" name=\"usrname\" value=\"$row['username']\">";

But i got this error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
kelvin sutanto
  • 113
  • 1
  • 2
  • 10

4 Answers4

1

You just need to wrap your $row['username'] with { }.

echo "<input type=\"text\" class=\"form-control\" placeholder=\"Username\" name=\"usrname\" value=\"{$row['username']}\">"; 
IsThisJavascript
  • 1,726
  • 2
  • 16
  • 25
1

It should work, plz try like below.

echo "<input type='text' class='form-control' placeholder='Username' name='usrname' value='".$row['username']."'>";
Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
Ayyappa amara
  • 437
  • 3
  • 16
0

Work like this:

echo "<input type=\"text\" class=\"form-control\" placeholder=\"Username\" name=\"usrname\" value=\"".$row['username']."\">";
Majid Abbasi
  • 1,531
  • 3
  • 12
  • 22
0

Here you go:

echo '<input type=\"text\" class=\"form-control\" placeholder=\"Username\" name=\"usrname\" value=\"'.$row['username'].'">';
Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33