dongxiz5342 2016-04-29 03:59 采纳率: 100%
浏览 33

条件,如果搜索栏为null则返回错误html

I created a search bar in html that searches my mySQL database and displays the results for my search.

My problem is that if I haven't typed anything on the bar it will display the whole table when I do not want that.

My code is this

<form action="Artists.php" method="post">
    <input type="text" name="searchdatabase"<br><br>
    <input type="submit" name="searching" value="Search"><br><br>

and I am trying to do this

  <?php 

      if( ! mysqli_num_rows($resultsearch) ) {
      echo "Mysql error: " .mysqli_error($mysql); }

      while($row =  mysqli_fetch_array($resultsearch)):?>
          <tr>
              <td><?php echo $row['firstname'];?></td>
              <td><?php echo $row['lastname'];?></td>

          </tr>
  <?php endwhile;?>

But this is not working, I am trying to create an if statement on html (I cant use Javascript) so that my code will not display my entire table and will only display the search I wanted once I press the search button.

  • 写回答

2条回答 默认 最新

  • dongmei8460 2016-04-29 04:26
    关注

    Why do you have endwhile? Just use {} for your loop, match your searchdatabase to one of your names in the mysql. If it doesn't appear in the database throw a error. Other wise have it display. Right now you are calling your whole table. $blah = $con, "Select * From somedata where searchdatabase = firstName"; if you need to order by a certain way order by asce or something like that hope that helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图