drjtua5953 2013-05-27 04:07
浏览 211
已采纳

如果值为空则不显示任何内容

On one file I have this code:

if (theForm.lqd_9.value == "")
{
    alert("You have forgotten to specify - Description!");
    theForm.lqd_9.focus();
    return (false);      
    <tr>
       <td class="theadingt" align="center" height="14" width="180">
             <b>Description:<span lang="en-us"><font color="#ff0000">*</font></span></b></td>
        <td class="theading" align="left" height="14" width="545">
    <textarea cols='48' rows='6' name="lqd_9"></textarea></td>
   </tr>

and on the receiving file I have this:

<?php echo $_POST["lqd_9"]; ?>

How can I make the code to not display anything if it's left empty?

  • 写回答

5条回答 默认 最新

  • dsnhalq37505 2013-05-27 04:11
    关注

    You could use methods like isset or empty

    <?php 
    if(isset($_POST["lqd_9"])){
     echo $_POST["lqd_9"];
    } 
    ?>
    

    OR

    <?php 
    if(!empty($_POST["lqd_9"])){
     echo $_POST["lqd_9"];
    } 
    ?>
    

    update

    It's better to use both as below.

    <?php 
    if(isset($_POST["lqd_9"]) && !empty($_POST["lqd_9"])){
     echo $_POST["lqd_9"];
    } 
    ?>
    

    PHP isset() vs empty() vs is_null()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码