Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP/MySQL中出现意外的T_常量_封装_字符串错误_Php_Mysql - Fatal编程技术网

PHP/MySQL中出现意外的T_常量_封装_字符串错误

PHP/MySQL中出现意外的T_常量_封装_字符串错误,php,mysql,Php,Mysql,因此,我尝试在PHP中运行一个查询,虽然查询本身没有错误(或者看起来没有),但编辑器在“echo”语句中看到了一个错误。代码如下: <?php include("include/session.php"); ?> <?php $db = new PDO('mysql:host=localhost;dbname=cvtool;charset=utf8', 'user', 'pass'); // change these to your own database

因此,我尝试在PHP中运行一个查询,虽然查询本身没有错误(或者看起来没有),但编辑器在“echo”语句中看到了一个错误。代码如下:

<?php
    include("include/session.php");
?>

<?php

    $db = new PDO('mysql:host=localhost;dbname=cvtool;charset=utf8', 'user', 'pass'); // change these to your own database details
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // later, change ERRMODE_WARNING to ERRMODE_EXCEPTION so users wont see any errors
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

    $department = isset($_GET['department'])? $_GET['department']: null;

    $sql = 'SELECT *
            FROM education
            WHERE school  LIKE ?;

    $q = $conn->prepare($sql);
    $q->execute(array('%$department%');
    $q->setFetchMode(PDO::FETCH_ASSOC);

    while ($r = $q->fetch()) {
        echo sprintf('%$department', $r['school']);
    }
 ?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <!--The viewport tag is used in order to scale the page properly inside any screen size -->
        <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <title>CV Tool</title>
        <link rel="shortcut icon" href="images/favicon.ico" />
        <link rel="stylesheet" href="css/main.css"/>
        <!--Import JQuery from stored file -->
        <script src="js/jquery-1.11.1.min.js"></script>
        <!--Import JQuery from Google's Content Delivery Network -->
        <!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">-->
        <link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css'>
        <script type="text/javascript" src="js/menu.js"></script>
        <script type="text/javascript" src="js/backToTop.js"></script>
    </head>
    <body>
        <!--Big wrapper contains the whole site (header,navigation menu,....,footer-->
        <div id="big_wrapper">
            <header id="top_header">
                <a href="main.php"><img src="images/cvlogo.png"> </a>

            </header>
            <br>
            <nav class="clearfix">
                <ul class="clearfix">
                <li><a href="main.php">Home</a></li>
                <?php
                    /**
                     * User has already logged in, so display relavent links, including
                     * a link to the admin center if the user is an administrator.
                     */
                    if($session->logged_in){

                        echo "<li><a href=\"search.php\">Search</a></li>"
                             ."<li><a href=\"myCVs.php\">My CV(s)</a></li>"
                             ."<li><a href=\"userinfo.php?user=$session->username\">My Account</a></li>"
                             ;

                        echo "<li><a href=\"process.php\">Logout</a></li>";
                    }
                else
                ?>

                </ul>
                <a href="#" id="pull">Menu</a>
            </nav>
            <section id="main_section"> 

            <table class="table table-bordered table-condensed">
            <thead>
            <tr>
        <th>Department</th>
        </tr>
        </thead>
        <tbody>
        <?php while ($r = $q->fetch()): ?>
        <tr>
        <td><?php echo htmlspecialchars($r['school'])?></td>

        </tr>
<?php endwhile; ?>
            </section>
            <footer id="the_footer">
                City CV Tool 2014
            </footer>
        <a href="#" class="back-to-top"></a>
        </div>
    </body>
</html>

错误可能只是遗漏了什么,或者是我在没有意识到的情况下放了一些额外的东西。我知道代码是关于一个非常具体的案例的,但是仍然非常感谢您的帮助。

您永远不会关闭以下字符串变量:

 $sql = 'SELECT *
         FROM education
         WHERE school  LIKE ?;

缺少一个引号
学校在哪里-注意到语法突出显示了吗?是的,我现在注意到了。由于某种原因,我使用的编辑器没有显示这一点,因此我没有想到错误就在那里。您使用的是哪个编辑器?PHP Designer 8。它通常会显示有错误的行和突出显示的语法,但我不知道为什么这次没有。嗯,比扎罗。好吧,如果这样的事情再次发生;在点击“发布您的问题”按钮之前,先看看堆栈的语法高亮显示是如何呈现代码的。很多时候,这会很有帮助,而且很可能会马上给出答案。我没有想到要查看缺少报价的查询。
 $sql = 'SELECT *
         FROM education
         WHERE school  LIKE ?;