我有一个文件名为fopen
,另一个文件名为showRelayTeams.php
我正在尝试将具有数据库功能的那个放到一个名为databaseSELECTOperation.php
showRelayTeam.php
showRelayTeams.php
databaseSELECTOperation.php
<?php
$House = $_GET['q'];
$Data = "No Data";
$Query = "SELECT Firstname, Lastname, AgeGroup, Event, Value FROM tblEventEntries WHERE House = '" . $House . "' ORDER BY Value ASC;";
require("http://127.0.0.1/phpscripts/databaseOperations.php");
$Data = databaseSELECTOperation($Query);
$Counter = 0;
if (mysqli_num_rows($Data) > 0) {
echo "<table>";
echo "<tr>";
echo "<th>Name</th>";
echo "<th>Age Group</th>";
echo "<th>Event</th>";
echo "<th>Time</th>";
echo "<th>Select?</th>";
echo "</tr>";
while ($Row = mysqli_fetch_assoc($Data)) {
$Counter++;
echo "<tr>";
echo "<td>" . $Row["Firstname"] . " " . $Row["Lastname"] . "</td>";
echo "<td>" . $Row["AgeGroup"] . "</td>";
echo "<td>" . $Row["Event"] . "</td>";
echo "<td>" . $Row["Value"] . "</td>";
echo "<td><input type='checkbox' id='" . $Counter . "'
onclick='boxChecked(this.id)'></td>";
echo "</tr>";
}
}
echo "</table>";
?>
我收到以下错误:
致命错误:未捕获错误:调用未定义函数databaseSELECTOperation()
当我在require语句之后插入以下代码时,我得到了
找不到功能
<?php
//use the SQL SELECT command and return the data
function databaseSELECTOperation($Query) {
//this file will include the host, username, password and the database name
include "http://127.0.0.1/includes/variables.php";
//start a connection to the database using the credentials
$Connection = mysqli_connect($DatabaseHost, $Username, $Password, $DatabaseName);
//if the connection to the database was not successfully made then
if (!$Connection) {
//end the script and then print an error
die("Could not connect to the database: " . mysqli_error());
} //end if
//run the query and put the data returned in to a variable
$DataReturned = mysqli_query($Connection, $Query);
//return the data to the script that called it
return $DataReturned;
}
?>
关于如何解决此问题的任何想法?
答案 0 :(得分:1)
那是错误:
require("http://127.0.0.1/phpscripts/databaseOperations.php");
当您通过URL引用文件时,它包括Web服务器已经处理的输出,而您需要包括源PHP代码。
相反,您需要像以下示例一样在文件系统上指定文件的路径:
require('../phpscripts/databaseOperations.php');
require('/var/www/html/phpscripts/databaseOperations.php');
require('C:\inetpub\html\phpscripts\databaseOperations.php');