2017-08-07 3 views
-1

私は間違ったユーザー名またはパスワードを入力するたびにポップアップするメッセージボックスを持っています。これどうやってするの? jqueryやjavascriptなど、あなたにとって快適なものを使用できます。私のコードはすでにユーザー名またはパスワードが間違っている場合、メッセージボックスを作成するにはどうすればよいですか?

<?php 
session_start(); 
?> 
<link rel="stylesheet" type="text/css" href="stylelog.css"> 
<html> 
<head> 
<title></title> 
<img src='imageslogin/background.png' style='position:fixed; 
top:0px;left:0px;width:100%;height:100%;z-index:-1;'> 

</head> 
<body> 
<header> 
<nav> 
    <div class="main-wrapper"> 
    <ul> 
     <li><a href="index.php"><img src='imageslogin/logo.png'></a></li> 
    </ul> 
     <div class="nav-login"> 
     <?php 
     if (isset($_SESSION['user_id'])){ 
      echo '<form action="includes/logout.inc.php" method="POST"> 
     <button type="submit" name="submit">Logout</button> 
     </form>'; 
     }else{ 
      echo '<form action= "includes/login.inc.php" method="POST"> 
    <input type="text" name="uid" placeholder="Username"required> 
    <input type="password" name="pwd" placeholder="Password" required> 
       <button type="submit" name="submit">Login</button> 
      </form>'; 
     } 
     ?> 

     </div> 
    </div> 
</nav> 
</header> 

......私はメッセージボックスがI入力中に間違っ詳細フォームの

コードをポップアップ表示されます方法を知りたいので、それをデバッグする必要が作業していませんで、ログのコードが.....

<?php 
require_once 'dbh.inc.php'; 

if (isset($_POST['submit'])) 
{ 
$uid = $_POST['uid']; 
$pwd = $_POST['pwd']; 

if($uid == "" || $pwd == "") 
{ 
    echo '<div id ="errormsg">Please fill in all fields</div>'; 
} 
else 
{ 
    $stmt = $DBcon->prepare("SELECT * FROM tbl_users Where username=? 
AND password=?");//prepare database, connect query it. 

これはdbh.inc.phpで作成されたPODである

$stmt->bindParam(1, $_POST['uid']);//bind parameters 
    $stmt->bindParam(2, $_POST['pwd']);//bind parameters 
    $stmt->execute(); 
    $row = $stmt->fetch();//get the row of the user ID in the database 
    $user = $row['username']; 
    $pass = $row['password']; 
    $id = $row['user_id']; 
    $type = $row['type']; 

      if ($uid==$user && $pwd==$pass && $type == "Administrator") 
      { 
       session_start(); 
       $_SESSION['user_id'] = $id; 
       $_SESSION['username'] = $user; 
       $_SESSION['password'] = $pass; 
       $_SESSION['type'] = $type; 
       header("location: ../Main_page.php"); 
      }//check if user password and member type 
    matches the inputted user credentials and is an administrator, 
    it will open main.php 
      else if ($uid == $user && $pwd == $pass && $type == "Member") 
      { 
       session_start(); 
       $_SESSION['user_id'] = $id; 
       $_SESSION['username'] = $user; 
       $_SESSION['password'] = $pass; 
       $_SESSION['type'] = $type; 
       header("location: ../user.php"); 
      }//check if user password and member type matches the inputted  
     user credentials and is an member, it will open user.php 
      else 
      { 
    header("location: ../index.php?=Error_loging_in_user_not_found"); 
      //echo '<div id="errormsg">User Not Found, try again</div>';  
      } 
     } 
    } 
    ?> 
+0

**自分でコードを書き込もうとしています**。あなたが問題を抱えている場合は** [もっと研究している**](https://meta.stackoverflow.com/q/261592/1011527)の後**あなたが試したものを投稿してください** **動作しておらず、[最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)を提供しています。 [質問する](http://stackoverflow.com/help/how-to-ask)の良い質問をお読みください。 [ツアーに参加する](http://stackoverflow.com/tour)と[this](https://meta.stackoverflow.com/q/347937/1011527)を必ずお読みください。 –

+0

**プレーンテキストのパスワードを保存しないでください!** *** PHPの[組み込み関数](http://jayblanchard.net/proper_password_hashing_with_PHP.html)***を使用してパスワードセキュリティを処理してください。 5.5より小さいPHPバージョンを使用している場合、 'password_hash()' [互換パック](https://github.com/ircmaxell/password_compat)を使用することができます。 ***ハッシュする前に[パスワードをエスケープする](http://stackoverflow.com/q/36628418/1011527)***または他のクレンジングメカニズムを使用する必要はありません。パスワードを変更すると、パスワードが変更され、不要な追加のコーディングが発生します。 –

答えて

0

Yあなたは要素としてechoを介して必要な情報を出力した後、document.getElementById('your_id')を使用してそれを取得し、それを要素に貼り付けてからcssという形式にしなければなりません。

関連する問題