/    Sign up×
Community /Pin to ProfileBookmark

PHP Fatal error: Uncaught Error: Call to undefined function

Having retrieved an associative array from a query, I’ve looped through and using the values, I wish to pass into a function which runs another query

I’ve done this but its constantly throwing out the error:

PHP Fatal error: Uncaught Error: Call to undefined function getDishtypeTitlesandPrice() in /home/mnzsm9leak30/public_html/test2.php:3156
Stack trace:
#0 {main}
thrown in /home/mnzsm9leak30/public_html/test2.php on line 3156

[code]
if($arrky == ‘subcategory_title’) {
$subcategorytitle_title = $arrval;

getDishtypeTitlesandPrice($subcategorytitle_title);


?>
<div class=”<?php echo strtolower(str_replace(‘ ‘, ”, $subcategorytitle_title)); ?>”>
<div class=”<?php echo strtolower(str_replace(‘ ‘, ”, $subcategorytitle_title)) . “-titledescription”; ?>”>
<div class=”<?php echo strtolower(str_replace(‘ ‘, ”, $subcategorytitle_title)) . “-title”; ?>”>
<div class=”row”>
<div class=”col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12″>
<h3 class=”<?php echo strtolower(str_replace(‘ ‘, ”, $subcategorytitle_title)); ?>”>
<?php echo $subcategorytitle_title; ?>
</h3>
</div>
</div>
</div>

<?php

function getDishtypeTitlesandPrice(&$str_title)
{
?>
<div class=”<?php echo strtolower(str_replace(‘ ‘, ”, $str_title)) . “-typetitle-price”; ?>”>
<?php

$subcategory_dishtypetitleprice = $connect->query(“SELECT MenuItemTitle, MenuItemType, MenuItemPrice FROM tblMenuItem LEFT JOIN lkuTbl_SubCategory ON FK_SubCategoryId = lkuTbl_SubCategory_PK_SubCategoryId WHERE lkuTbl_SubCategory_SubCategoryTitle = ‘$str_title'”);
while ($dishtypetitleprice_subcategory = $subcategory_dishtypetitleprice->fetch_assoc())
{
$traditfavourites_dishes[$dishtypetitleprice_subcategory[‘MenuItemTitle’]][] = array(
‘type’ => $dishtypetitleprice_subcategory[‘MenuItemType’],
‘price’ => $dishtypetitleprice_subcategory[‘MenuItemPrice’]
);
}

?>
</div>
<?php
}

}
[/code]

yes I do know I would need to rework the div classes (<?php echo strtolower(str_replace(‘ ‘, ”, $str_title)) . “-typetitle-price”; ?>)

the error line being 3156 which is the function call itself or before ( getDishtypeTitlesandPrice($subcategorytitle_title);
)

I’ve checked scope but don’t see or understand what’s wrong, Can someone help?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmNov 05.2019 — Your function has its own share of errors but to get past the error you are currently getting, try moving the function outside of the block of code it is currently in. Define it separate from the rest of your code instead of inside an if statement. Then be sure that things you are using inside the function are reachable or passed into it.

PS - do you really enjoy using camel case in your names knowing that php is case-sensitive and can be the source of lots of little niggling errors when you simply mis-type one of those loooong names that you are using?
Copy linkTweet thisAlerts:
@nsathauthorNov 05.2019 — @ginerjm#1610664

Thank you!!!

Camel case yes I know PHP is case-sensitive but Its an old habit from years of Java Programming
Copy linkTweet thisAlerts:
@NogDogNov 05.2019 — For your own sanity's sake, I'd recommend _not_ outputting directly from within the function, but instead having it return whatever you want output, then echo it from within the main part of the script. Simplified greatly:
<i>
</i>&lt;h1&gt;Hello, World&lt;/h1&gt;
&lt;p&gt;&lt;?php echo myFunc($_POST['foo']); ?&gt;&lt;/p&gt;
&lt;p&gt;The end.&lt;/p&gt;

&lt;?php
function myFunc($foo)
{
$results = someAmazingDBFuction($foo);
return sprintf(
"&lt;a href='%s'&gt;%s&lt;/a&gt;",
$results['link'],
htmlspecialchars($results['text'])
);
return $output;
}

In any case, you're going to need to pass your DB $connect variable into the function as well, so that it can do the DB stuff.
×

Success!

Help @nsath spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...