为什么我的程序无法在函数中回显变量?

时间:2019-04-20 23:25:05

标签: php

所以我有三个php文件。第一个包含HTML表单和对第二个php文件的操作。第二个文件包括第三个php文件,总共三个文件。当用户提交HTML表单时,第二个php文件将正确显示。但是,第二个文件应该从位于第三个文件中的函数回显一个变量,但事实并非如此。此变量在第三个文件中声明。所有文件都在同一目录中。

我能够从函数成功回显文字字符串。我也能够简单地在第二个文件中回显该变量,而不必在第三个文件中调用该函数。即使在第三个文件中定义了此变量,该操作仍然成功。

第一个文件

<html>
<head>
  <title> Searching for volunteers </title>
</head>

<body>
  <h3> Provide search criteria below. </h3>

  <form action="queryResults.php" method="post">
    <h4> Primary Days for Volunteers </h4>
    <input type="checkbox" name="mondays" value="mondays"> Mondays
    <input type="checkbox" name="wednesdays" value="wednesdays"> Wednesdays <br><br>

    <h4> Volunteer Roles </h4>
    <input type="checkbox" name="director" value="director"> Director
    <input type="checkbox" name="supportStaff" value="supportStaff"> Support Staff <br><br>

    <input type="submit" value="Submit">
  </form>

</body>
</html>

第二个文件,名为queryResults.php

<html>
<head>
  <title> Query results </title>
</head>
<body>

<?php

  include "buildQuery.php";

  buildQueryy();

?>


</body>
</html>

第三个文件,名为buildQuery.php

<html>
<head>
  <title> Building query </title>
</head>
<body>
<?php
  /* Variables */

  $sqlQueryy = "SELECT DISTINCT Volunteers.firstName, Volunteers.lastName, c.emailAddress, c.primaryPhoneNumber, c.secondaryPhoneNumber FROM Volunteers AS v, ContactInfo AS c INNER JOIN Volunteers ON c.id = Volunteers.id";

  /* Functions */

  function buildQueryy () {
    echo "This line prints fine";
    echo $sqlQueryy; // this variable doesn't print to the screen.

  }

 ?>
</body>
</html>

0 个答案:

没有答案
相关问题