My ajax-call posts the data loadingaid1
along with some other data. In my php-file I then request the value and assign it to $loadingaid1
. So far so good.
What I know want to do is to call the function getProductId
which selects the respective id out of my database and override the variable $loadingaid1
with that ID.
The code I tried is the following:
(...)
$loadingaid1 = $_REQUEST['loadingaid1'];
$loadingaid1 = getProductId($loadingaid1);
(...)
function getProductId($product) {
$stmt = $conn->prepare('SELECT idproducts FROM products WHERE title = :product LIMIT 1');
if ($stmt->execute(array(':product' => $product))) {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row['idproducts'];
};
}
But somehow the code always fails as soon as I bring the function into the game. What am I doing wrong?
The prepared statement is correct - already compared it several times to my column & table names and working statements that basically do the same thing. And the requested value saved in loadingaid1 also exists in the table.