dongmo6937 2014-05-24 17:27
浏览 52
已采纳

使用echo POSTBACK值回显输入字段

So I'm iterating through a set value via a for loop, which will echo html input fields, every other echo'd html input field behaves as expected (including the name and id fields of the one below), however I keep getting syntax errors when trying to set the value as a postback to retain them on page submit. Here is my code:

$type = "number".$i;
echo '<input type="text" name="'.$type.'" id="'.$type.'" value="'.<?php if (isset($_POST[$type])) { echo $_POST[$type]; } else { echo NULL;}.'" />';

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douyinglan2599 2014-05-24 17:31
    关注

    You have an extra <?php statement in the row. Since the line is echo '...'. you don't need to declare that more php code is coming. You can do something like this instead:

    echo '<input type="text" name="'.$type.'" id="'.$type.'" value="';
    if (isset($_POST[$type])) echo $_POST[$type];
    echo '" />';
    

    Although personally, I prefer to do something like <input [...] id="{$type}" [...]" outside of the php code, less messy.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!