2015-07-10 73 views
0

我有一個登錄PHP的形式,當用戶鍵入不正確的證書,那麼它會輸出「名或密碼錯誤」,然而這是在導航網站上面的頂部擺正。這裏有一個截圖:http://imgur.com/IAsaMWH樣式文本由輸出文件撰寫

我想將文本放置在網站包裝和一個div內,以便我可以用css編輯它。

我一直在使用document.getElementById('log').innerHTML但是這隻能當格「日誌」是PHP代碼上面的嘗試,但是PHP已經留在上面,否則我得到一個錯誤:

Warning: session_start(): Cannot send session cache limiter - headers already sent

這裏我的php/js

總之,我想要做的是當登錄憑證錯誤時,向用戶顯示一條消息「不正確的用戶名或密碼」我需要使用CSS編輯此消息,因爲我需要將其重新放置在頁面上。 如果有人能夠編輯我的代碼並向我解釋他們做了什麼 - 這將非常感激。

這是我的PHP與JS:

<?php 
session_start(); 
include_once 'dbconnect.php'; 

if(isset($_SESSION['user'])!="") 
{ 
header("Location: account.php"); 
} 
if(isset($_POST['btn-login'])) 
{ 
$email = mysql_real_escape_string($_POST['email']); 
$upass = mysql_real_escape_string($_POST['pass']); 
$res=mysql_query("SELECT * FROM users WHERE email='$email'"); 
$row=mysql_fetch_array($res); 
if($row['password']==md5($upass)) 
{ 
    $_SESSION['user'] = $row['user_id']; 
    header("Location: account.php"); 
} 
else 
{ 
    ?> 
     <script>document.write('Incorrect Username or Password');</script> 
     <?php 
} 

} 
?> 

這裏是我的HTML

<?php include"authentication/login.php";?> 

<!DOCTYPE html> 
<html> 
<HEAD> 
<title>Website | Loign</title> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<?php include "includes/page_sources.php"; ?> 

</HEAD> 
<body> 


<?php include "includes/navigation.php"; ?> 

<div id="wrapper"> 



<div id="login-form"> 
    <form method="post"> 
     <input type="text" name="email" placeholder="Your Email" required /> 
     <input type="password" name="pass" placeholder="Your Password" required /> 
     <button type="submit" name="btn-login">Log In</button> 
     <a href="register.php">Sign Up</a> 
    </form> 
</div> 



</div> 

<?php include "includes/footer.php"; ?> 


</body> 
</html> 

再次感謝你的幫助提前

+0

的PHP無關了這個問題。我們需要呈現的HTML和CSS。 – j08691

+0

你需要網站的圖像嗎?或者我應該添加頁面的CSS代碼? –

回答

2

有沒有在你的榜樣各種錯誤。無論你在哪裏放置你的PHP代碼:如果你想追加某些div的東西 - 然後延遲,直到dom加載。你最好使用jquery或者有一個「domReady」函數的東西,但是你也可以不使用它。相反,你的文件撰寫腳本,你可以只說:

window.onload = function() { document.getElementById('something').innerHTML = 'some html'; }; 

上面一行將等待要加載的文件,它現在能夠找到即使PHP代碼是高於一切的股利。

1

這實在是很容易做,在這種方式

PHP文件:

<?php 
session_start(); 
include_once 'dbconnect.php'; 
$error="no"; 
if(isset($_SESSION['user'])!="") 
{ 
header("Location: account.php"); 
} 
if(isset($_POST['btn-login'])) 
{ 
$email = mysql_real_escape_string($_POST['email']); 
$upass = mysql_real_escape_string($_POST['pass']); 
$res=mysql_query("SELECT * FROM users WHERE email='$email'"); 
$row=mysql_fetch_array($res); 
if($row['password']==md5($upass)) 
{ 
    $_SESSION['user'] = $row['user_id']; 
    header("Location: account.php"); 
} 
else 
{ 
$error="yes"; 
} 

} 
?> 

HTML:

<?php include"authentication/login.php";?> 

    <!DOCTYPE html> 
    <html> 
    <HEAD> 
    <title>Website | Loign</title> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <?php include "includes/page_sources.php"; ?> 

    </HEAD> 
    <body> 


    <?php include "includes/navigation.php"; ?> 

    <div id="wrapper"> 



    <div id="login-form"> 
     <form method="post"> 
<?php if($error=="yes") echo 'Incorrect Username or Password';?> 
      <input type="text" name="email" placeholder="Your Email" required /> 
      <input type="password" name="pass" placeholder="Your Password" required /> 
      <button type="submit" name="btn-login">Log In</button> 
      <a href="register.php">Sign Up</a> 
     </form> 
    </div> 



    </div> 

    <?php include "includes/footer.php"; ?> 


    </body> 
    </html>