即使搜索字段为空,如何停止搜索字段给出结果?

时间:2015-09-28 19:51:08

标签: html

我创建了一个简单的搜索引擎,可以在数据库中返回结果,但是......

单击“搜索”按钮时,即使搜索字段为空,它也会立即返回数据库中的所有结果。

感谢您的帮助,

的index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Burning Flame Search</title>

<script src='nprogress.js'></script>
<link rel='stylesheet' href='nprogress.css'/>

<Style>

*{margin:0px;
    padding:0px;
    }

    #menu {
    height:38px;
    padding-top:0px;
    background-color:white;
    text-align: center;
    }

    .photo {
        position:relative;
        font-family:arial;  
        overflow:hidden;
        border:0px;
        width:811px;
        height:98px;
        margin-left:250px;
    }   

        .photo .heading, .photo .caption {
    position:absolute;
    background:#000;
    height:50px;
    width:816px;
    opacity:0.6;
        }

        .photo .heading { 
            top:-50px;
        }

        .photo .caption {
    bottom:-42px;
    left:3px;
        }

        .photo .heading span {
            color:#26c3e5;  
            top:-50px;
            font-weight:bold;
            display:block;
            padding:5px 0 0 10px;
        }

        .photo .caption span{
            color:#FF0;
            font-size:16px;
            display:block;
            padding:5px 10px 0 10px;
        }

    .footer {
    font-family: Calibri;
    font-size: 18px;
    color: #000;
}
#menu ul li {
    display: inline-block;
    margin: 5px;
}
    .footer a {
    text-align: center;
}
    .menuhead {
    font-family: Calibri;
}
    .menuhead {
    font-size: 24px;
}
    .menuhead {
    font-size: 18px;
}
    .footer1 {
    text-align: left;
    font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    font-size: 18px;
    color: #000;
}
#submit {
    -webkit-border-radius: 2;
    -moz-border-radius: 2;
    border-radius: 2px;
    font-family: Arial;
    color: #9E9E9E;
    font-size: 20px;
    background: #EEEEEE;
    padding: 10px 20px 10px 20px;
    border: solid #EEEEEE 0px;
    text-decoration: none;
}
#submit:hover {
    background: #E0E0E0;
    text-decoration: none;
}

img, object{
    max-height:100%;
    max-width:100%;
    pointer-events: none;
}

text, object{
    max-height:100%;
    max-width:100%;
}
input[type="text"] {
    max-height:99%;
    max-width:85%;
    height:34px;
    padding-left: 5px;
    border: 1px solid #E0E0E0;
    box-shadow: 1px 1px 1px #E0E0E0;
}
</style>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css">
</head>
<body>
    <div id="menu">
     <ul id="MenuBar1" class="MenuBarHorizontal">
      <li><a href="/search/books/index.html">Books</a></li>
      <li><a href="/search/list.php">Add Url</a></li>
      <li><a href="#">About Us</a></li>
      <li><a href="#">Contact Us</a></li>
    </ul>
</div>

    <p><center>
      <p class="menuhead"><br>
      </p>
      <br>
    </center>

</div>
<center>
<p class="footer1">&nbsp;</p>
<p class="footer1">&nbsp;</p>
<p class="footer1">&nbsp;</p>
<p class="footer1">&nbsp;</p>
<p class="footer1">&nbsp;</p>
<img src="images/logo1.png"/>
</center>
<form action="/search/search.php" method='GET'>

  <center> 
    <p><br>
    </p>
    <p>&nbsp;</p>
    <p>
      <input name='search' type='text' class="footer1" size='50'></font></p>
    <p>&nbsp;</p>
  </center>


<p class="footer1"><center>
  <input name='submit' type='submit' id="submit" class="footer1" value='Search Burning Flame'>
  </center>
</p>
</form>
<p class="footer1">&nbsp;</p>
<p class="footer1">&nbsp;</p>
<p class="footer1">&nbsp;</p>
<p class="footer1">&nbsp;</p>
<p class="footer1">&nbsp;</p>
<p class="footer1">
<p class="footer1">
<p class="footer1">
<center>

<script type="text/javascript">
  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
</center></p>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

在你的search.php中,将此代码添加到现有逻辑之上(事实上在if else中)。

    <?php

      if(!empty($_POST['search_term'])){
       //Your Existing Logic
      }
     else{
      echo 'No results/You should enter a keyword';
     }
   ?>