dtn36013 2016-10-28 06:22
浏览 31

在某些条件下,在我的HTML页面中创建一个对话框

What I need to do.... In php-part of my login.php I check the user password and login this way:

<?php

// some code

session_start();
$query = "SELECT * FROM CRM.Users WHERE Login = '$l_username' AND Password = '$l_password'";
$result = mysql_query($query) or die ( "Error : ".mysql_error() ); 
while($row = mysql_fetch_assoc($result)){

... 

if(mysql_num_rows($result) < 1){

// echo The password or login is wrong  

</php>

In My HTML i have:

<div id="dialog" title="Basic dialog">
  <p>The password or login is wrong</p>
</div>

And in my JS part I have:

function myfunction() 
    {

     $( function() {
       $( "#dialog" ).dialog();
     } );

}

But when I bind MyFunction() with some test submit button (by onClick event) I see the DIV part in my page like common html text. But I dont want to see it while the condition wont true. So, My questions:

  1. How I can realize the password/login check, throwing dialog box and when User click OK, i want to pull out user to index.php page
  2. How I can hide the DIV for Dialog while condition is false
  • 写回答

2条回答 默认 最新

  • dslk6326846 2016-10-28 06:44
    关注

    Here is the code for your problem:

    <?php
    if(mysql_num_rows($result) < 1) {
    ?>
    <script>
    $(function(){
      myFunction();
    });
    </script>
    <?php }?>
    
    <script>
        function myfunction() 
        {
            $("#dialog").dialog({
              resizable: false,
              modal: true,
              buttons: {
                OK: function() {
                  $( this ).dialog( "close" );
                  window.location = 'http://localhost';
                }
              }
            });
        }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入