In my php file

echo "<script>alert('Username/password pair is invalid.Please try again.')</script>";
echo"<script language='javascript'>window.location.href='login.php'</script>";

I am displaying message like this but when message is displayed background php design is blank and then again login page display.

I want show message like http://www.bin-co.com/javascript/examples/print.php#
when we click on Create Alert message is display with background php design

How to do this???

Hi,
The background will be blank only as the control is first going to the alert function ;
You can do like this.........
You have this alert and location inside two functions and call them when required...

can you give me example code for..
How to call alert??

CHECK THIS OUT...

<script>
function AL(){
alert("Test message");
}
</script>
<script type="text/javascript">
function te(){
window.location.href="YOURFILE.php";
}
</script>
<?
echo "<a onClick=\"AL();\">Alert</a>";

echo "<a onClick=\"te();\">Location</a>";
?>
<script>
function AL(){
alert("Test message");
}
</script>
<script type="text/javascript">
function te(){
window.location.href="YOURFILE.php";
}
</script>


<?
if (isset($_POST['Submit']))
{
   query-----
 if( username and pass )
   {
  -----correct
   }
 else
 {
------How to call function AL() Here ???? 
 }
}
?>

YOU CAN USE THIS..TO AVOID THE BLAnk background.

echo "<form method='GET' >";
		echo "Enter you input :<input type='text' name='code'><br>";
		echo "<input type='submit' value='submit' name='sub'>";
		echo "</form>";
if($_REQUEST['sub']){
$con=mysql_connect("","","") or die(mysql_error());
	mysql_select_db('',$con) or die(mysql_error());
	$sql="SELECT * from TAB WHERE Date between CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 14 DAY)";
	$exe=mysql_query($sql) or die(mysql_error());
	if( mysql_num_rows($exe))
	echo "<script> alert(\"Test message\") </script>";
}

Hi,
The background will be blank only as the control is first going to the alert function ;
You can do like this.........
You have this alert and location inside two functions and call them when required...

I will just rephrase that to make it much more clearer.
"To show the page in the background, the alert(); script must be at the very bottom of the page where the footers would be." Functions are just another way of calling them.

I will just rephrase that to make it much more clearer.
"To show the page in the background, the alert(); script must be at the very bottom of the page where the footers would be." Functions are just another way of calling them.

script at bottom ??
And how to call it???

Example plz??

Well you shouldn't have to worry about how to call the functions as mentioned before my first reply and an example of what the page should look like is as below:

<?
echo "<html><head><title>Page Title</title></head><body>"; //headers
echo "any html code and general php code goes where this line is";
//so above was almost all of the script with the following at the very bottom
//below is based on an earlier example
if (isset($_POST['Submit']))
{
//   query-----
 if( username and pass )
    {
    echo"<script language='javascript'>window.location.href='login.php'</script>";
    }
} else {
echo "<script>alert('Username/password pair is invalid.Please try again.')</script>";
}
echo "</body></html>";
?>
<?
$mode=$_GET['mode'];
if($mode="postdata")
{
postdata();
}
?>

<html>
<head>
<title>LoginPage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet"  href="css/style.css" type="text/css" />
<script type="text/javascript"  src="JS/script.js"></script>
<SCRIPT LANGUAGE="JavaScript">
function AL()
 {
alert ("Ok, you did type ");
}
</SCRIPT>
</head>
<body>
<table width="92%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="top"><p><fieldset ><legend class="bluenormal1 style6" >Login</legend>
        <form action="login.php?postdata" method="post" name="loginform" id="loginform">
        <p><span class="style3"><span class="style6"><span class="style2">Welcome to the Front Office Administration Panel! </span><br>
          <br>
          <span class="style2"> please enter your username and password. </span></span></span></p>
        <p><span class="style3"><span class="style2"><br>
          <span class="style4"> Kindly login</span></span></span><span class="style5">.</span></p>
      <table width="28%"  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="28%" height="35"> <span class="style9">Username</span>&nbsp; </td>
              <td width="72%"><input name="user_uname" type="text" id="user_uname" size="30"></td>
            </tr>
            <tr>
              <td height="31"><span class="style9">Password </span></td>
              <td ><input name="user_pass" type="password" id="user_pass" size="30"></td>
            </tr>
            <tr>
              <td height="29"></td>
              <td  style="padding-left:55px" valign="middle"><input type="submit" name="Submit" value="Login" onClick="return formValidator()" ></td>
            </tr>
          </table> 
          <p>&nbsp;        </p>
      </form>
      <p class="style2">&nbsp; </p>
    </fieldset> </td>
  </tr>
</table>
 <p align="center"><span class="style2"></span> </p>
</body>
</html>

<?php
function postdata()
{
	$con = mysql_connect("localhost","root","");
	if (!$con)
	  {  die('Could not connect: ' . mysql_error());  }
	  else {// echo('Connected with Mysql'); }
		@mysql_select_db("db_assign2", $con);
		if (isset($_POST['Submit']))
	{
			$user_uname=$_POST["user_uname"];
			$user_pass=$_POST["user_pass"];
			//Second let's check if that username and password are correct and found in our database
		$sql=mysql_query("SELECT * FROM tbl_userinfo WHERE user_uname='$user_uname' AND user_pass='$user_pass'");
			
			if (mysql_num_rows($sql)==0 || mysql_num_rows($sql)>1)
			{	
				echo "<script>alert('Username/password pair is invalid.Please try again.')</script>";
				
				echo"<script language='javascript'>window.location.href='login.php'</script>";
			}
			while($row = mysql_fetch_array($sql))
				  {
				  	if($user_pass==$row['user_pass'] and $user_uname==$row['user_uname'])
					{
					$app_id=$row['app_id'];
						if($app_id==1)
						{
							$user_id =$row['user_id'];
							echo"<script language='javascript'>window.location.href='profile.php?mode=$user_id'</script>";
						}
						else
						{
						//echo "<a href=\"login.php\" onMouseMove=\"AL()\">aaa</a>";
						[B]//Here I want to dispaly alert message[/B]
//echo "<script>alert('Admin Is Not Approved Your Login.Please try again.')/script>";
				//echo"<script language='javascript'>window.location.href='login.php'/script>";
						}
					}
				  }
		} 
}
?>

ref link is http://javascript.internet.com/text-effects/confirm-alert.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.