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

¿Fue útil?

Solución

$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>';

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;

?>

DEMO
http://ideone.com/YuYmBs

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.'>';
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top