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

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

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条)

报告相同问题?