通过输出document.write来设置文本样式

时间:2015-07-10 18:19:10

标签: javascript php jquery html css

我有一个登录php表单,当用户键入不正确的凭据时,它将输出“不正确的用户名或密码”,但这是放在导航上方网站的顶部。以下是截图:http://imgur.com/IAsaMWH

我想将文本放在网站包装器内并在div中,以便我可以用css编辑它。

我尝试过使用document.getElementById('log').innerHTML但是只有当div“log”高于php代码时这才有效,但是php必须保持在顶部,否则我会收到错误:

  

警告:session_start():无法发送会话缓存限制器 - 标头   已发送

这是我的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>

再次感谢您提前获得任何帮助

2 个答案:

答案 0 :(得分:2)

你的例子中有各种各样的错误。你把PHP代码放在哪里并不重要:如果你想将某些东西附加到某种div上 - 那么就要延迟直到dom加载。你最好不要使用jquery或者有一个&#34; domReady&#34;功能可用,但你也可以没有它。你可以说:

而不是你的document.write脚本
string strUserName="abc";
string strPassword="123";
SecureString ssPwd = new SecureString();
strPassword.ToList().ForEach(ssPwd.AppendChar);
ClientContext context = new ClientContext(siteurl);
SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(strUserName, ssPwd);

context.Credentials = credentials;
// The SharePoint web at the URL.
Web web = context.Web;

// We want to retrieve the web's properties.
context.Load(web);

// Execute the query to the server.
context.ExecuteQuery();

上面的行会等待加载文档,即使php代码高于其他所有内容,现在也可以找到div。

答案 1 :(得分: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>
相关问题