Php 如果用户名和密码正确,则在同一页上显示消息

Php 如果用户名和密码正确,则在同一页上显示消息,php,html,Php,Html,我正在开发一个需要用户名和密码才能登录的应用程序。我正在使用dreamweaver进行开发。我想实现的是,当用户输入正确的用户名和密码时,他应该会收到一条消息,说“用户名和密码正确”,如果凭据错误,则说“用户名或密码错误”。 但对于Dreamweaver登录服务器行为,它无法做到这一点,它所做的是在凭据正确或错误时重定向到页面。有人能帮我吗 HTML PHP 更改标题位置(在php代码的最底部)?除非您根本不想刷新页面,否则您需要使用AJAX,尽管我不确定会话/登录是否是一个好主意/可能。

我正在开发一个需要用户名和密码才能登录的应用程序。我正在使用dreamweaver进行开发。我想实现的是,当用户输入正确的用户名和密码时,他应该会收到一条消息,说“用户名和密码正确”,如果凭据错误,则说“用户名或密码错误”。 但对于Dreamweaver登录服务器行为,它无法做到这一点,它所做的是在凭据正确或错误时重定向到页面。有人能帮我吗

HTML


PHP


更改标题位置(在php代码的最底部)?除非您根本不想刷新页面,否则您需要使用AJAX,尽管我不确定会话/登录是否是一个好主意/可能。(或者只需完全删除
标题()
位置)
  <form id="form2" name="form2" method="post" action="">
      <table width="100%" border="0" cellpadding="4" cellspacing="4">
        <tr>
          <td><label for="username"></label>
            <input name="username" type="text" class="register-input" id="username" data-role="none" placeholder="Enter your username" /></td>
        </tr>
        <tr>
          <td><label for="password"></label>
            <input name="password" type="text" class="register-input" id="password" data-role="none" placeholder="Enter your password" /></td>
        </tr>
        <tr>
          <td><input type="submit" name="button" id="button" value="Sign In" /></td>
    </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
      <table width="100%" border="0" cellpadding="4" cellspacing="4">
        <tr>
          <td><div align="center"> </div></td>
        </tr>
      </table>
    </form>
<?php require_once('Connections/db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "test.php";
  $MM_redirectLoginFailed = "error.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_catchapp, $catchapp);

  $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

  $LoginRS = mysql_query($LoginRS__query, $catchapp) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";

    if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;       

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>