Php 按页更改的值,无需输入

Php 按页更改的值,无需输入,php,sql,variables,Php,Sql,Variables,我有一个php页面更新sql数据库。我有4个字段作为访问日期。这是第一次访问第二次访问 问题是通过访问该页面,如果我没有给出值,所有日期都会设置为“0000-00-00”。我希望显示器显示空白 有没有办法不改变值 编辑:有四个文本框显示日历以输入日期。但是,我一次只添加一个日期,因此其他框不接收用户输入。尽管如此,在页面加载“空白”字段后,获取“0000-00-00” 然后显示0。我没有想到要改变显示而不是输入。我可以检查一下 以下两种解决方案似乎都不能阻止sql将字段更改为0000-00-00

我有一个php页面更新sql数据库。我有4个字段作为访问日期。这是第一次访问第二次访问

问题是通过访问该页面,如果我没有给出值,所有日期都会设置为“0000-00-00”。我希望显示器显示空白

有没有办法不改变值

编辑:有四个文本框显示日历以输入日期。但是,我一次只添加一个日期,因此其他框不接收用户输入。尽管如此,在页面加载“空白”字段后,获取“0000-00-00”

然后显示0。我没有想到要改变显示而不是输入。我可以检查一下

以下两种解决方案似乎都不能阻止sql将字段更改为0000-00-00。我突然想到,这可能只是sql对访问单元格的反应

  <tr>
                    <td class="LabelColumn" <?php addToolTip("Format: YYYY-MM-DD<br>or enter the date by clicking on the calendar icon to the right."); ?>><?php echo gettext("Friend Date1:"); ?></td>
                    <td class="TextColumn"><input type="text" name="FriendDate1" value="<?php echo $dFriendDate1; ?>" maxlength="10" id="sel1" size="11">&nbsp;<input type="image" onclick="return showCalendar('sel1', 'y-mm-dd');" src="Images/calendar.gif"> <span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo $sFriendDateError ?></font></td>
                </tr>

                <tr>
                    <td class="LabelColumn" <?php addToolTip("Format: YYYY-MM-DD<br>or enter the date by clicking on the calendar icon to the right."); ?>><?php echo gettext("Friend Date2:"); ?></td>
                    <td class="TextColumn"><input type="text" name="FriendDate2" value="<?php echo $dFriendDate2; ?>" maxlength="10" id="sel2" size="11">&nbsp;<input type="image" onclick="return showCalendar('sel2', 'y-mm-dd');" src="Images/calendar.gif"> <span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo $sFriendDateError ?></font></td>
                </tr>

                <tr>
                    <td class="LabelColumn" <?php addToolTip("Format: YYYY-MM-DD<br>or enter the date by clicking on the calendar icon to the right."); ?>><?php echo gettext("Friend Date3:"); ?></td>
                    <td class="TextColumn"><input type="text" name="FriendDate3" value="<?php echo $dFriendDate3; ?>" maxlength="10" id="sel3" size="11">&nbsp;<input type="image" onclick="return showCalendar('sel3', 'y-mm-dd');" src="Images/calendar.gif"> <span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo $sFriendDateError ?></font></td>
                </tr>

                <tr>
                    <td class="LabelColumn" <?php addToolTip("Format: YYYY-MM-DD<br>or enter the date by clicking on the calendar icon to the right."); ?>><?php echo gettext("Friend Date4:"); ?></td>
                    <td class="TextColumn"><input type="text" name="FriendDate4" value="<?php echo $dFriendDate4; ?>" maxlength="10" id="sel4" size="11">&nbsp;<input type="image" onclick="return showCalendar('sel4', 'y-mm-dd');" src="Images/calendar.gif"> <span class="SmallText"><?php echo gettext("[format: YYYY-MM-DD]"); ?></span><font color="red"><?php echo $sFriendDateError ?></font></td>
                </tr>

>

您可以通过一个简短的if语句轻松地实现这一点

例如:

value="<?php echo (!empty($dFriendDate3) && $dFriendDate3!='0000-00-00') ? $dFriendDate3 : ''; ?>"
value=“”

@skrilled的想法是正确的,但请尝试以下方法:

value="<?php echo $dFriendDate1 === '0000-00-00' ? '' : $dFriendDate1; ?>"
value=“”

如何设置
$dFriendDate1
等。?修正它。解释“不要给出一个值”。@skrilled的回答正确地处理了变量实际被设置为“0000-00-00”的情况,你的答案将显示为空白。这也不能处理变量为空的情况,这是最初的问题。