I have 2 functions that I can request with an url parameter. the strange thing is that one function is working while the other isn't.
this is my select.php code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// This function will select all data where productid is the same as the provided product id
function select_product_specific($productid)
{
GLOBAL $mysqli, $prefix;
$stmt = $mysqli->prepare("SELECT
*
FROM " . $prefix . "product
WHERE productid = ?");
$stmt->bind_param("i", $productid);
$stmt->execute();
$stmt->bind_result($productid, $productnaam, $productomschrijving);
while($stmt->fetch())
{
$row[] = array('productid' => $productid, 'productnaam' => $productnaam, 'productomschrijving' => $productomschrijving);
}
$stmt->close();
return($row);
}
function select_leverancier_specific($levid)
{
GLOBAL $mysqli, $prefix;
$stmt = $mysqli->prepare("SELECT
levid,
levnaam,
adres,
postcode,
woonplaats,
land,
telefoonnummer
FROM " . $prefix . "leverancier
WHERE levid = ?");
$stmt->bind_param("i", $levid);
$stmt->execute();
$stmt->bind_result($levid, $levnaam, $adres, $postcode, $woonplaats, $land, $telefoonnummer);
while($stmt->fetch())
{
$row[] = array('levid' => $levid, 'levnaam' => $levnaam, 'adres' => $adres, 'postcode' => $postcode, 'woonplaats' => $woonplaats, 'land' => $land, 'telefoonnummer' => $telefoonnummer);
}
$stmt->close();
return($row);
}
?>
I can request the function in request.php:
<?php
// Require file with connection to database
require_once('../connection/connect.php');
// Requite file with functions
require('../core/select/select_all.php');
require('../core/select/select.php');
// This file handles the request an app sends
// It will check what kind of function is requested,
// if the function needs some param's
// and then json_encode the output
@$function = $_GET['function'];
@$param = $_GET['param'];
if(!isset($_GET['function']))
{
$array = array('error' => 'Geen functie is aangeroepen!');
return json_encode($array);
}
elseif(!isset($_GET['param']))
{
var_dump(json_encode($function()));
}
else
{
### place 1 ###
var_dump(json_encode($function($param)));
}
?>
when enter the following url
request.php?function=select_leverancier_specific¶m=1
I get the following error:
Fatal error: Call to undefined function select_leverancier_specific() in ... line 29
Line 29 is
var_dump(json_encode($function($param)));
when I place the function select_leverancier_specific($levid) on the ###place 1### placeholder, I get the correct result.
when I request select_product_specific($productid) I get the correct result.
Does someone know where my error is?
Thanks a lot in advance!