dongshang1768
2014-05-10 09:58
浏览 247
已采纳

无法在html文本框中显示0值

I'm displaying data from mysql using php. You can see the value is 0 for Current Balance But in edit mode it cant display 0

enter image description here

Before executing update statement

I declare its variable from its corresponding $_POST variable

if (!empty($_POST)) {

    $ID = $_POST['ID'];
    $Name = $_POST['Name'];
    $AID = $_POST['AID'];
    $CurrentBalance = $_POST['CurrentBalance'];

    $valid = true;

    if ($valid) {
        $setsu = dbSetsuzoku();
        $setsu->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "UPDATE tabledb SET ID = ?, Name = ?, AID=?, CurrentBalance=? WHERE SubAgentID = ?";
        $q = $setsu->prepare($sql);
        $q->execute(array($ID,$Name,$AID,$CurrentBalance,$ID));
        $setsu = null;
    }
} 
 else {
    $setsu = dbSetsuzoku();
    $setsu->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "SELECT * FROM tabledb where ID = ?";
    $q = $setsu->prepare($sql);
    $q->execute(array($ID));
    $data = $q->fetch(PDO::FETCH_ASSOC);
    $ID = $data['ID'];
    $Name = $data['Name'];
    $AID = $data['AID'];
    $CurrentBalance = $data['CurrentBalance'];
    $setsu = null;
}

html (edit mode)

<input name="CurrentBalance" type="text" placeholder="CurrentBalance" value="<?php echo !empty($CurrentBalance)?$CurrentBalance:'';?>" required />

other fields follow the same logic

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dsbx40787736 2014-05-10 10:05
    最佳回答

    The problem is :

    <?php echo !empty($CurrentBalance)?$CurrentBalance:'';?>
    

    For empty function 0 is considered as empty - just look at http://au2.php.net/manual/en/function.empty.php

    You can change it into:

    <?php echo isset($CurrentBalance)?$CurrentBalance:'';?>
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题