1

I have a form that is filled out once a year per customer, but some fields stay constant (birthday for example). So my goal is when a new customer fills out the form for the first time the birthday field is a text box, but after they fill out the form the first time and come back next year it just displays their birthday but does not allow them to edit it (echo's the birthday, not simply shows it in the text box).

What I have now is below, the goal of this statement is to check if there is a value in the SQL field, if so echo that value, else echo a text box. I keep getting an error when I try and load the form and I think its just a syntax error somewhere.

<?php
if($bday!="") //if bday field is not empty
{
echo $bday; //display bday field value
}
else
{           
echo '<input type=text name=bday size=12 maxlength=12 value='<?php echo htmlentities ($bday, ENT_QUOTES) ?>'>'; //else echo the text box
}
?>
4

1 回答 1

2

您已经在编写 PHP,因此您不必在 echo 语句中再次使用开始和结束标记。改为使用字符串连接(使用点)。尝试这个:

echo '<input type=text name=bday size=12 maxlength=12 value="'.htmlentities($bday, ENT_QUOTES).'">';

但是,如果 $bday=="",为什么要用它作为文本框的值呢?

于 2012-10-25T14:12:48.450 回答