dongzhang1864 2013-09-15 16:41
浏览 44

模态对话框不起作用

In this below code i want to display data in modal window .My aim is to display the searched data in modal dialog .Actual result is they are displaying above the form.I have tried some steps but i cant able to produce the expected result pls help me.

<?php  
$search = (isset($_POST['search']) ? $_POST['search'] : null);

  mysql_connect("localhost", "root", "") OR die (mysql_error());
  mysql_select_db ("slseatapp") or die(mysql_error());

 $query = "SELECT * FROM coursemaster WHERE course_code LIKE '%$search%' or course_name like '%$search%'"; 

  $result = mysql_query($query) or die (mysql_error());

   $msg ;
     if($result) 
     {    
        while($row=mysql_fetch_row($result))   
       {      
            $msg=$msg ."ID=".$row[0].",COURSE CODE=".$row[1].",COURSE NAME=".$row[2];


       }   
      echo"<script>function overlay(){

el = document.getElementById('overlay');
el.style.visibility = (el.style.visibility == 'visible') ? 'hidden' : 'visible';

}function close() {
     document.getElementById('overlay').style.visibility = 'hidden';
}</script>";
echo"<style>#overlay div {
     width:300px;
     margin: 100px auto;
     background-color: #fff;
     border:1px solid #000;
     padding:15px;
     text-align:center;
}</style>";
        echo"<div id='overlay'>('$msg ');</div>";  
     }
   else
     { 
       echo "No result";  
     }
 ?>

<form action="look.php" method="post">  
 <center> SEARCH:<input type="text" name="search" placeholder="SEARCH"><br></center>  
 <center> <input type="submit" name="hhhh" class="btn-success btn"></center>
</form>  
  • 写回答

1条回答 默认 最新

  • duanbi3385 2013-09-15 20:20
    关注

    Some tipps for you: try to use PDO instead of deprecated mysql functions, don't mix php code with html/js, don't mix css with html, for a better browser compatibility use jQuery instead of native Javascript, also don't use deprecated HTML-Tags like 'center'-Tag, don't try to build your own modal dialog, its better to use jQuery-UI, at last format your code. To your problem, debug your code and see if result exists. You can also check your console output for js-errors.

    For me looks like your javascript code try to get overlay element before this element is rendered by browser. Put your js code to the end of your html document. And where do you call overlay function?

    Another tipp: Fire your search query only if $search is not null and escape user variables in your query, e.g. with mysql_real_escape_string or prepared statements with PDO, to prevent sql-injection.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c