$pid=$row['P_ID'];
echo '<form>';
echo '<input type="text" name="history" value= '.$pid.'>'; // This line will be change.
echo '<input type="submit" value="View Patient History">';
echo '</form>';
How to display sql variable in the input tag of HTML? [closed]
Pregunta
I assigned the sql value in $pid
, if i click the button, i wanted the P_ID
value to be store in the "value"
.
Code:
echo '<form>';
$pid=$row['P_ID'];
echo '<input type="text" name="history" value= '$pid'>';
echo '<input type="submit" value="View Patient History">';
echo '</form>';
However, I received few errors:
SCREAM: Error suppression ignored for Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';'
Thank you
Solución
Otros consejos
You have to append the php variable to the string using dot operator
echo '<input type="text" name="history" value="'.$pid.'">';
Use PHP HEREDOC function (<<< EOF
), this way you don't need to escape any single or double quotes and it helps you to read the html code, it's a time saver.
<?php
$pid=$row['P_ID'];
echo <<< EOF
<form>
<input type="text" name="history" value= "$pid">
<input type="submit" value="View Patient History">
</form>
EOF;
?>
Just amend the third line of your code to say -
echo '<input type="text" name="history" value= '.$pid.'>';
instead of
echo '<input type="text" name="history" value= '$pid'>';
From the knowledge I've got from SO,
I think echo '<input type="text" name="history" value= '$pid'>';
should be:
echo '<input type="text" name="history" value= '.$pid.'>';