Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1511
  • Last Modified:

Create Php Login Error Message Alert

Hello

Can anyone show me how to alert a user to enter a username & password or alert them to the fact that their username/password is incorrect please?

txt file attached admin_login.php

Thanks


php-login-page.txt
0
kevinb4940
Asked:
kevinb4940
  • 4
  • 2
2 Solutions
 
Ali KayahanFull Stack DeveloperCommented:

<?php require_once('Connections/mcm_listings_db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}
 
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
 
if (isset($_POST['name'])) {
  $loginUsername=$_POST['name'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "admin_home.php";
  $MM_redirectLoginFailed = "admin_login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_mcm_listings_db, $mcm_listings_db);
  
  $LoginRS__query=sprintf("SELECT name, password FROM `admin` WHERE name=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $mcm_listings_db) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      
 
    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
   echo "Your user name or password is incorrect" ; 
    #header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 
<title>Donegal Real Estate MCM</title>
 
<link href="mcm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
 
<body>
<div id="wrapper">
<table width="800" align="center">
  <tr>
    <td valign="top">
	<table width="800"  border="0" class="boxes">
      <tr>
        <td class="logo" width="714" >&nbsp;</td>
        <td width="86">
          <div align="right"><img src="images/corner-image.gif" alt="" width="85" height="75" /></div></td>
      </tr>
      <tr>
        <td height="24" colspan="2" align="center"><div id="navigation">
            <ul>
              <li><a href="index.php">Home</a></li>
|
<li><a href="contact.php">Contact</a></li>
|
<li><a href="services.php" class="tablerow">Services</a></li>
|
<li><a href="residential.php" class="tablerow">Residential Property</a></li>
|
<li><a href="newhomes.php">New Homes</a></li>
|
<li><a href="saleagreed.php">Sale Agreed</a></li>
|
<li><a href="commercial.php">Commercial Property</a></li>
|
<li><a href="land.php">Land/Sites</a></li>
</ul>
        </div></td>
      </tr>
      <tr>        </tr>
      <tr>
        <td height="86" colspan="2" valign="top">
		<table width="804" >
          <tr>          </tr>
          <tr>            </tr>
          <tr>          </tr>
          <tr>          </tr>
          
          
          <tr>          </tr>
          <tr>            </tr>
        </table>
		<table width="800" border="0">
          <tr>
           
            <td width="181" align="center" valign="top" class="leftcol">
              
             <form METHOD="POST" name="form1" id="form1">
                          <p class="titletext">Property Search                             </p>
                          
                            <select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
                              <option value="#" selected="selected">Property Type</option>
                              <option value="residential.php">Residential </option>
                              <option value="newhomes.php">New Homes</option>
                              <option value="saleagreed.php">Sale Agreed </option>
                              <option value="commercial.php">Commercial</option>
                              <option value="land.php">Land / Sites</option>
                            </select>
                  </form><br />
              <p class="titletext">Site Search</p>
             
                <p>
                  <select name="menu2" onchange="MM_jumpMenu('parent',this,0)">
                    <option selected="selected">Please Select</option>
                    <option value="sales.php">Property Sales</option>
                    <option value="architecture.php">Architecture</option>
                    <option value="auctioneering.php">Auctioneering</option>
                    <option value="valuation.php">Valuation</option>
                    <option value="valuation.php">Surveying</option>
                      </select>
                </p>
                <p class="titletext">Contact Us</p>
                <p class="address">McM Auctioneers </p>
                <p class="address">Meetinghouse Street</p>
                <p class="address">Raphoe </p>
                <p class="address">County Donegal</p>
                <p class="address">Tel: 07491 45400</p>
                <p class="address">Fax: 074991 45437</p>
                <p class="address">Mobile: 087 288 7639</p>
				<p class="address">(Dial 00353 from UK)</p>
                <br />
                <p class="address">Click Below to Email </p>
                <p align="center"><a href="mailto:mcmauctioneers@eircom.net"><img src="/images/redmail.jpg" alt="" width="60" height="30" class="email" /></a></p>                
                <p>&nbsp; </p></td>
			
			
            <td width="602" rowspan="4" valign="top">              <div id="center_content">
                <p align="left" class="text">Admin Login</p>
                  <form id="form2" name="form2" method="POST" action="<?php echo $loginFormAction; ?>">
                    <table border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>Username</td>
                        <td>&nbsp;<input type="text" name="name" id="name" /></td>
                      </tr>
                      <tr>
                        <td>Password</td>
                        <td>&nbsp;<input type="password" name="password" id="password" /></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
                      </tr>
                      </table>
                                </form>
                  <p align="left" class="text">&nbsp;</p>
              </div></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<div class="footer"><a href="admin_login.php">Admin login</a>  | © Copyright 2007 | Site Design by Kevin Blakely| info@onevisionwebdesign.co.uk| www.onevisionwebdesign.co.uk </div>
</div>
</body>
</html>

Open in new window

0
 
kevinb4940Author Commented:
Thanks a lot

There is slight problem though. The error message appears outside the table.

Sorry for being so fussy!
0
 
kevinb4940Author Commented:
Sorry Again

I just realised that you cannot see the page
http://www.donegalrealestate.com/admin_login.php
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Ali KayahanFull Stack DeveloperCommented:
Can you please try
<?php require_once('Connections/mcm_listings_db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}
 
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
 
if (isset($_POST['name'])) {
  $loginUsername=$_POST['name'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "admin_home.php";
  $MM_redirectLoginFailed = "admin_login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_mcm_listings_db, $mcm_listings_db);
  
  $LoginRS__query=sprintf("SELECT name, password FROM `admin` WHERE name=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $mcm_listings_db) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      
 
    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
   $message = "Your user name or password is incorrect" ; 
    #header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 
<title>Donegal Real Estate MCM</title>
 
<link href="mcm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
 
<body>
<div id="wrapper">
<table width="800" align="center">
	<tr><?php empty($message) ? echo $message : true ?></tr>
  <tr>
    <td valign="top">
	<table width="800"  border="0" class="boxes">
      <tr>
        <td class="logo" width="714" >&nbsp;</td>
        <td width="86">
          <div align="right"><img src="images/corner-image.gif" alt="" width="85" height="75" /></div></td>
      </tr>
      <tr>
        <td height="24" colspan="2" align="center"><div id="navigation">
            <ul>
              <li><a href="index.php">Home</a></li>
|
<li><a href="contact.php">Contact</a></li>
|
<li><a href="services.php" class="tablerow">Services</a></li>
|
<li><a href="residential.php" class="tablerow">Residential Property</a></li>
|
<li><a href="newhomes.php">New Homes</a></li>
|
<li><a href="saleagreed.php">Sale Agreed</a></li>
|
<li><a href="commercial.php">Commercial Property</a></li>
|
<li><a href="land.php">Land/Sites</a></li>
</ul>
        </div></td>
      </tr>
      <tr>        </tr>
      <tr>
        <td height="86" colspan="2" valign="top">
		<table width="804" >
          <tr>          </tr>
          <tr>            </tr>
          <tr>          </tr>
          <tr>          </tr>
          
          
          <tr>          </tr>
          <tr>            </tr>
        </table>
		<table width="800" border="0">
          <tr>
           
            <td width="181" align="center" valign="top" class="leftcol">
              
             <form METHOD="POST" name="form1" id="form1">
                          <p class="titletext">Property Search                             </p>
                          
                            <select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
                              <option value="#" selected="selected">Property Type</option>
                              <option value="residential.php">Residential </option>
                              <option value="newhomes.php">New Homes</option>
                              <option value="saleagreed.php">Sale Agreed </option>
                              <option value="commercial.php">Commercial</option>
                              <option value="land.php">Land / Sites</option>
                            </select>
                  </form><br />
              <p class="titletext">Site Search</p>
             
                <p>
                  <select name="menu2" onchange="MM_jumpMenu('parent',this,0)">
                    <option selected="selected">Please Select</option>
                    <option value="sales.php">Property Sales</option>
                    <option value="architecture.php">Architecture</option>
                    <option value="auctioneering.php">Auctioneering</option>
                    <option value="valuation.php">Valuation</option>
                    <option value="valuation.php">Surveying</option>
                      </select>
                </p>
                <p class="titletext">Contact Us</p>
                <p class="address">McM Auctioneers </p>
                <p class="address">Meetinghouse Street</p>
                <p class="address">Raphoe </p>
                <p class="address">County Donegal</p>
                <p class="address">Tel: 07491 45400</p>
                <p class="address">Fax: 074991 45437</p>
                <p class="address">Mobile: 087 288 7639</p>
				<p class="address">(Dial 00353 from UK)</p>
                <br />
                <p class="address">Click Below to Email </p>
                <p align="center"><a href="mailto:mcmauctioneers@eircom.net"><img src="/images/redmail.jpg" alt="" width="60" height="30" class="email" /></a></p>                
                <p>&nbsp; </p></td>
			
			
            <td width="602" rowspan="4" valign="top">              <div id="center_content">
                <p align="left" class="text">Admin Login</p>
                  <form id="form2" name="form2" method="POST" action="<?php echo $loginFormAction; ?>">
                    <table border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>Username</td>
                        <td>&nbsp;<input type="text" name="name" id="name" /></td>
                      </tr>
                      <tr>
                        <td>Password</td>
                        <td>&nbsp;<input type="password" name="password" id="password" /></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
                      </tr>
                      </table>
                                </form>
                  <p align="left" class="text">&nbsp;</p>
              </div></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<div class="footer"><a href="admin_login.php">Admin login</a>  | © Copyright 2007 | Site Design by Kevin Blakely| info@onevisionwebdesign.co.uk| www.onevisionwebdesign.co.uk </div>
</div>
</body>
</html>

Open in new window

0
 
Ali KayahanFull Stack DeveloperCommented:
Which page you mean ?
0
 
Ali KayahanFull Stack DeveloperCommented:
The one below should work
<?php require_once('Connections/mcm_listings_db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}
 
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
 
if (isset($_POST['name'])) {
  $loginUsername=$_POST['name'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "admin_home.php";
  $MM_redirectLoginFailed = "admin_login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_mcm_listings_db, $mcm_listings_db);
  
  $LoginRS__query=sprintf("SELECT name, password FROM `admin` WHERE name=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $mcm_listings_db) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      
 
    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
   $message = "Your user name or password is incorrect" ; 
    #header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 
<title>Donegal Real Estate MCM</title>
 
<link href="mcm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
 
<body>
<div id="wrapper">
<table width="800" align="center">
  <tr>
    <td valign="top">
	<table width="800"  border="0" class="boxes">
      <tr>
        <td class="logo" width="714" >&nbsp;</td>
        <td width="86">
          <div align="right"><img src="images/corner-image.gif" alt="" width="85" height="75" /></div></td>
      </tr>
      <tr>
        <td height="24" colspan="2" align="center"><div id="navigation">
            <ul>
              <li><a href="index.php">Home</a></li>
|
<li><a href="contact.php">Contact</a></li>
|
<li><a href="services.php" class="tablerow">Services</a></li>
|
<li><a href="residential.php" class="tablerow">Residential Property</a></li>
|
<li><a href="newhomes.php">New Homes</a></li>
|
<li><a href="saleagreed.php">Sale Agreed</a></li>
|
<li><a href="commercial.php">Commercial Property</a></li>
|
<li><a href="land.php">Land/Sites</a></li>
</ul>
        </div></td>
      </tr>
      <tr>        </tr>
      <tr>
        <td height="86" colspan="2" valign="top">
		<table width="804" >
          <tr>          </tr>
          <tr>            </tr>
          <tr>          </tr>
          <tr>          </tr>
          
          
          <tr>          </tr>
          <tr>            </tr>
        </table>
		<table width="800" border="0">
          <tr>
           
            <td width="181" align="center" valign="top" class="leftcol">
              
             <form METHOD="POST" name="form1" id="form1">
                          <p class="titletext">Property Search                             </p>
                          
                            <select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
                              <option value="#" selected="selected">Property Type</option>
                              <option value="residential.php">Residential </option>
                              <option value="newhomes.php">New Homes</option>
                              <option value="saleagreed.php">Sale Agreed </option>
                              <option value="commercial.php">Commercial</option>
                              <option value="land.php">Land / Sites</option>
                            </select>
                  </form><br />
              <p class="titletext">Site Search</p>
             
                <p>
                  <select name="menu2" onchange="MM_jumpMenu('parent',this,0)">
                    <option selected="selected">Please Select</option>
                    <option value="sales.php">Property Sales</option>
                    <option value="architecture.php">Architecture</option>
                    <option value="auctioneering.php">Auctioneering</option>
                    <option value="valuation.php">Valuation</option>
                    <option value="valuation.php">Surveying</option>
                      </select>
                </p>
                <p class="titletext">Contact Us</p>
                <p class="address">McM Auctioneers </p>
                <p class="address">Meetinghouse Street</p>
                <p class="address">Raphoe </p>
                <p class="address">County Donegal</p>
                <p class="address">Tel: 07491 45400</p>
                <p class="address">Fax: 074991 45437</p>
                <p class="address">Mobile: 087 288 7639</p>
				<p class="address">(Dial 00353 from UK)</p>
                <br />
                <p class="address">Click Below to Email </p>
                <p align="center"><a href="mailto:mcmauctioneers@eircom.net"><img src="/images/redmail.jpg" alt="" width="60" height="30" class="email" /></a></p>                
                <p>&nbsp; </p></td>
			<td><?php !empty($message) ? echo $message : true ?></td>
			
            <td width="602" rowspan="4" valign="top">              <div id="center_content">
                <p align="left" class="text">Admin Login</p>
                  <form id="form2" name="form2" method="POST" action="<?php echo $loginFormAction; ?>">
                    <table border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>Username</td>
                        <td>&nbsp;<input type="text" name="name" id="name" /></td>
                      </tr>
                      <tr>
                        <td>Password</td>
                        <td>&nbsp;<input type="password" name="password" id="password" /></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
                      </tr>
                      </table>
                                </form>
                  <p align="left" class="text">&nbsp;</p>
              </div></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<div class="footer"><a href="admin_login.php">Admin login</a>  | © Copyright 2007 | Site Design by Kevin Blakely| info@onevisionwebdesign.co.uk| www.onevisionwebdesign.co.uk </div>
</div>
</body>
</html>

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now