1

I have one file called showRelayTeams.php and another called databaseSELECTOperation.php

I am trying to put the one with the database function into the one called showRelayTeams.php

showRelayTeam.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.php

<?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;
}
?>

I get the following error:

Fatal error: Uncaught Error: Call to undefined function databaseSELECTOperation()

When I insert the following code just after the require statement, I get

function not found

<?php
if (function_exists('databaseSELECTOperation')) {
    echo "function found.<br />\n";
} else {
    echo "function not found<br />\n";
}
?>

Any ideas on how to solve this?

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83

1 Answers1

1

That is the error:

require("http://127.0.0.1/phpscripts/databaseOperations.php");

When you are referring to the file via URL, it is including the output which is already processed by a web server, while you need to include the source PHP code.

Instead, you need to specify the path to the file on the file system like in the following examples:

require('../phpscripts/databaseOperations.php');
require('/var/www/html/phpscripts/databaseOperations.php');
require('C:\inetpub\html\phpscripts\databaseOperations.php');
Elvis Plesky
  • 3,190
  • 1
  • 12
  • 21