在某些条件下,在我的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

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>

Your code is fine. It just needs some cleaning up:

<?php
if (!isset($_SESSION)) {
    session_start();
}


$query = "SELECT *
FROM CRM.Users
WHERE Login = '".mysql_real_escape_string($l_username)."'
AND Password = '".mysql_real_escape_string($l_password)."'
LIMIT 1";

$resource = mysql_query($query) or die ("Error : ".mysql_error() );

// If there is one result, the login is successfull
if (mysql_num_rows($result) == 1) {
    $record = mysql_fetch_assoc($resource);
    $_SESSION['user'] = array(
        'id' => $record['id'],
        'username' => $record['Username'];
    );

    // Redirect
    header("Location: secure.php");
    exit;
}
?>

To check if a user is logged in:

if (!isset($_SESSION['user'])) {
    header("Location: login.php");
    exit;
}

Note: Others will probably complain about mysql_* functions not being secure. and they are right. These functions are deprecated. Instead I recommend using mysqli_*

Update

I forgot the part where the question was about hehe. Adding a dialog can be done very easily.

<script type="text/javascript">
if(!confirm("...")) return;
// redirect here
</script>