HTTP错误500 PHP

时间:2016-07-04 18:26:12

标签: php pdo

我的网站上收到HTTP错误500。 PHP代码检查器没有看到任何可疑的东西。 我认为这是由PDO引起的,但我不确定,因为当我删除所有PHP代码时,它仍然给我同样的错误。 这是我的代码: 的index.php:

<?php
    include_once('includes/db_connect.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable="no>
    <!-- Custom CSS -->
    <link rel="stylesheet" href="css/custom.css">
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css" />
    <!-- Optional theme (flatly) -->
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootswatch/latest/flatly/bootstrap.min.css" />
    <!-- Font awesome -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/contact.css" rel="stylesheet">
    <!-- jQuery -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script src="js/contact.js"></script>
    <!-- Latest compiled and minified JavaScript -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/latest/js/bootstrap.min.js"></script>

    <title><?php
        foreach($dbh->query('SELECT * FROM page_info') as $row) {
            echo $row['title'];
        }
        ?></title>
</head>
<body>
    <div class="banner">
        <div class="name"><?php
        foreach ($dbh->query('SELECT * FROM page_info') as $row) {
            echo $row[“name”];
        }
                ?></div>
    </div>
    <div class="about">
        <div class="about-container">
            <div class="about-main-text">
                <h1>About me:</h1>
                <?php
                    foreach ($dbh->query('SELECT * FROM about') as $row) {
                    echo '
                        <span>'.$row["text"].'</span>
                    ';
                }
                ?>
            </div>
        </div>
    </div>
    <div class="projects">
        <div class="projects-container">
            <div class="projects-main-text">
                <h1>My projects:</h1>
            </div>
            <div class="row">
                <?php
                  foreach($dbh->query('SELECT * FROM projects') as $row) {
                      echo '
                            <div class="col-md-4 nopadding">
                                 <div class="project-box">
                                      <img src="data:image/jpeg;base64,'.base64_encode( $row['image'] ).'" alt="Project Image">
                                      <h1>'.$row["name"].'</h1>
                                      <p>'.$row["desc"].'</p>
                                 </div>
                            </div>
                      ';
                  }
                ?>
            </div>
        </div>
    </div>
    <div class="contact">
        <div class="contact-container">
            <div class="contact-main-text">
                <h1>Contact me:</h1>
            </div>
            <div class="row">
                <form action="contact/send.php" method="post" style="float: left;">
                    <div class="field name-box">
                        <input type="text" id="name" name="name" placeholder="Who Are You?"/>
                        <label for="name">Name</label>
                        <span class="ss-icon">check</span>
                    </div>

                    <div class="field email-box">
                        <input type="text" id="email" name="email" placeholder="name@email.com"/>
                        <label for="email">Email</label>
                        <span class="ss-icon">check</span>
                    </div>

                    <div class="field msg-box">
                        <textarea id="msg" rows="4" placeholder="Your message goes here..."/></textarea>
                        <label for="msg">Msg</label>
                        <span class="ss-icon">check</span>
                    </div>

                    <input class="button" type="submit" value="Send" />
                </form>
            </div>
        </div>
    </div>
    <div class="footer">
        <span class="copyright">
            &copy; <?php
                foreach ($dbh->query('SELECT * FROM page_info') as $row) {
                    echo $row['copyright'];
                }
            echo ' ' . date("Y");
?> - All rights reserved
        </span>
    </div>
</body>
</html>

这是db_connect.php:

<?php

    $uname = ‘rik_root’;
    $upass = ‘*********’;

    $dbh = new PDO('mysql:host=localhost;dbname=nijdeken’, $uname, $upass);

?>

我希望有人可以帮助我。提前谢谢!

1 个答案:

答案 0 :(得分:2)

请勿使用文字处理程序编辑代码:

$uname = ‘rik_root’;
         ^--------^

那些不是有效的php引用字符,并且可能使用致命的解析错误来杀死你的代码:

$dbh = new PDO('mysql:host=localhost;dbname=nijdeken’, $uname, $upass);
               ^--start of string                   ^--NOT an end-of-string