Jump to content

How to fix "Fatal error: Call to undefined function"


pioneerx01

Recommended Posts

$query  = "SELECT * FROM School_Registrations WHERE School_Name= '$_POST[schoolName]' ";
$result2 = mysql_query($query);
if (mysql_numrows($result2) > 0) {
while($row = mysql_fetch_array($result2))
{
echo" 
<h2>ERROR</h2>
...rest of the error code...
";} 
}
else {

mysql_query("INSERT INTO ``.`` (...all the variables...);") 

or die(mysql_error( 'Location: http://www...php' ));  

echo "
...success code...


$url = 'http://www.mypage.com/page.php?';
$url .= 'email='.urlencode($_POST['email']);

$result = getPage('', $url, '', 15);

function getPage($proxy, $url, $header, $timeout) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_REFERER, 'http://mypage.org');
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0. Gecko/2009032609 Firefox/3.0.8');
    $result['EXE'] = curl_exec($ch);
    $result['INF'] = curl_getinfo($ch);
    $result['ERR'] = curl_error($ch);
    curl_close($ch);
    return $result;
}
}
?>

 

Ok, so this code verifies what the name entered in the forms is not already in database. If it is it gives you the ...error code... and nothing else. If it does not it gives you ...success code... and it creates new table record, and it sends out email address entered to designated page. Bu I keep getting:

 

Fatal error: Call to undefined function getPage()

 

It still fully works, but no email goes out as defined. I am stuck. Help?

Link to comment
Share on other sites

@Pika, Because php is a parsed/tokenized/interpreted language, function definitions in the main program scope are resolved at parse time and the definition can be after the call.

 

However, if the function definition is inside a conditional statement (I'm sure of this one) or in an include file (I'm not 100% sure of this one Just tested and I'm sure of this one too), they are resolved at runtime and the definition must exist before the call.

Link to comment
Share on other sites

Maq: True I have forgotten {} around the statement, but that did not help anything. Problem is still there.

Pikachu2000: Since this is all new to me, and Google search did not yield any viable solutions for how to Define the function before use, can you help me out on that one?

Zurev: I need that code to be "activated" only when there are no results in the database. I do not know any other way of doing that but the way I have it now.

PFMaBiSmAd: I don't even know what you have said ...  :confused:

Link to comment
Share on other sites

Maq: True I have forgotten {} around the statement, but that did not help anything. Problem is still there.

Pikachu2000: Since this is all new to me, and Google search did not yield any viable solutions for how to Define the function before use, can you help me out on that one?

Zurev: I need that code to be "activated" only when there are no results in the database. I do not know any other way of doing that but the way I have it now.

PFMaBiSmAd: I don't even know what you have said ...  :confused:

 

Add a "; after your success code... and let us know if the situation persists.

Link to comment
Share on other sites

I have put it in right after the die statement and before the $url =

 

$query  = "SELECT * FROM School_Registrations WHERE School_Name= '$_POST[schoolName]' ";
$result2 = mysql_query($query);
if (mysql_numrows($result2) > 0) {
while($row = mysql_fetch_array($result2))
{
echo" 
<h2>ERROR</h2>
...rest of the error code...
";} 
}
else {

mysql_query("INSERT INTO ``.`` (...all the variables...);") 

or die(mysql_error( 'Location: http://www...php' ));  

{
echo "
<h2>Registration for <em> $_POST[schoolName] </em> has been submitted.</h2>
  <p>You will receive an email to <em> $_POST[email] </em>, within few minutes confirming your registration. If this address is incorrect, or you do not receive this email, please <a href='../contactus.shtml'>contact us</a>.</p>
  <p>At this time you may begin registering your <a href='teacher.php'>teachers</a>. </p>
  <p> Some email providers can mark AzSEF email correspondence as span, thus your confirmation email may end up in spam or trash folder. <br>
    To ensure delivery please add myemail to your contact list.</p>
  <p>Thank you</p>
  <p><a href='../feedback.shtml'>Submit a feedback about this registration...</a></p>
  <div align='right'><a href='../onlineregistration101.shtml'>NEXT</a> ><br>
  </div></td>
</tr>
</table>";}

$url = 'http://www.mypage.com/page.php?';
$url .= 'email='.urlencode($_POST['email']);

$result = getPage('', $url, '', 15);

function getPage($proxy, $url, $header, $timeout) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_REFERER, 'http://mypage.org');
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0. Gecko/2009032609 Firefox/3.0.8');
    $result['EXE'] = curl_exec($ch);
    $result['INF'] = curl_getinfo($ch);
    $result['ERR'] = curl_error($ch);
    curl_close($ch);
    return $result;
}
}
?>

Link to comment
Share on other sites

Actually, someone has already posted why, in your code, you need to put the function definition before it is called -

 

if the function definition is inside a conditional statement ... they are resolved at runtime and the definition must exist before the call.

 

Your function definition is inside your else{} conditional statement. It would actually help if you indented your code properly so that you can see what code is at the same level. If you cannot see which code is part of the else{} statement, it is kind of hard to debug what your code is.

Link to comment
Share on other sites

Try just moving the

@Pika, Because php is a parsed/tokenized/interpreted language, function definitions in the main program scope are resolved at parse time and the definition can be after the call.

 

However, if the function definition is inside a conditional statement (I'm sure of this one) or in an include file (I'm not 100% sure of this one Just tested and I'm sure of this one too), they are resolved at runtime and the definition must exist before the call.

 

Ah, that's why. About 99.99% of the functions I write are in include()d files, and even if they aren't I always define them before calling them. Thanks for taking the time to answer that.

Link to comment
Share on other sites

Well yes. That code (where the error is) needs to be used only when the else statement is satisfied and only then. How else would I do it?

 

Move this line down below the closing curly brace for the function definition, but before the curly brace that closes the else statement. See if you still get the same error.

$result = getPage('', $url, '', 15);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.