简体   繁体   中英

Modal dialog box is not working

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>  

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, eg with mysql_real_escape_string or prepared statements with PDO, to prevent sql-injection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM