-4

我是 php 新手,我需要有关此代码的帮助,因为当我尝试加载它时,我得到“HTTP-fout 500(内部服务器错误):”。有人可以发布整个好的代码。谢谢。

      <?php
    session_start();


    if(empty($_POST['username']) || empty($_POST['password'])) {
    $notifications[] = 'Login failed! Please provide a username and password.';
   }

       if(count($notifications) == 0) {
    try {
        $dbh = new PDO('mysql:dbname=db33936_axe;host=mysql12-int.cp.hostnet.nl',   
    'u33936_mick', '123');

        $sql = "SELECT username, verified FROM users WHERE username = :username AND    
    password = :password";
        $sth = $dbh->prepare($sql);
        $sth->execute(array(
            ':username'    => $_POST['username'],
            ':password' => md5($_POST['password'])
        ));

        $result = $sth->fetch(PDO::FETCH_ASSOC);

        if($result) {
            // Set session details and redirect user to members page
            session_regenerate_id();
        $_SESSION['username']=':username';
        $_SESSION['password']=':password';

            header('Location: index.php');
        } else {
            $notifications[] = "Username or Password incorrect.";
        }
4

3 回答 3

1

你有不匹配的报价。试试这个:

echo "<li id='login'>

<a id='login-trigger' href='#'>

或者,您可以像这样逃避它们:

<a id=\"login-trigger\" href=\"#\">

或者只是将开头和结尾的双引号更改echo为单引号。echo对语句中的所有引号执行此操作。

于 2013-06-27T16:29:43.883 回答
0

用于 echo 语句的双引号 " 被用于 html 标记的双引号关闭,在每个 " 之前放置反斜杠,如下所示:

echo "<a href=\"#\">link</a>";
于 2013-06-27T16:29:51.957 回答
0

您可以像这样用单引号引用该长字符串:

echo '<li id="login">
    ...
</li>';
于 2013-06-27T16:33:49.887 回答