pioneerx01 Posted January 6, 2011 Share Posted January 6, 2011 $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? Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/ Share on other sites More sharing options...
Pikachu2000 Posted January 6, 2011 Share Posted January 6, 2011 Define the function before you try to use it. Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155832 Share on other sites More sharing options...
Maq Posted January 6, 2011 Share Posted January 6, 2011 Define the function before you try to use it. That doesn't matter. I don't see how you're not seeing a fatal error for not closing your echo string: echo " ...success code... Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155835 Share on other sites More sharing options...
Pikachu2000 Posted January 6, 2011 Share Posted January 6, 2011 Why have I always thought functions needed to be defined before being called? Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155836 Share on other sites More sharing options...
Zurev Posted January 6, 2011 Share Posted January 6, 2011 And clearly the function isn't defined because it's still in the echo string, is that what everyone else is seeing? Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155842 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2011 Share Posted January 6, 2011 @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. Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155847 Share on other sites More sharing options...
pioneerx01 Posted January 6, 2011 Author Share Posted January 6, 2011 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 ... Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155851 Share on other sites More sharing options...
Zurev Posted January 6, 2011 Share Posted January 6, 2011 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 ... Add a "; after your success code... and let us know if the situation persists. Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155858 Share on other sites More sharing options...
Maq Posted January 6, 2011 Share Posted January 6, 2011 Post your updated code with the exact error message. Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155860 Share on other sites More sharing options...
pioneerx01 Posted January 6, 2011 Author Share Posted January 6, 2011 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155874 Share on other sites More sharing options...
Maq Posted January 6, 2011 Share Posted January 6, 2011 Post your updated code with the exact error message. Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155878 Share on other sites More sharing options...
pioneerx01 Posted January 6, 2011 Author Share Posted January 6, 2011 ops sorry. I get the entire success code (with new record in the designated table) and this message at the end: Fatal error: Call to undefined function getPage() in /home/azsef/public_html/register/school_finished.php on line 120 Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155879 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2011 Share Posted January 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155882 Share on other sites More sharing options...
pioneerx01 Posted January 6, 2011 Author Share Posted January 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155883 Share on other sites More sharing options...
Pikachu2000 Posted January 6, 2011 Share Posted January 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155909 Share on other sites More sharing options...
Pikachu2000 Posted January 6, 2011 Share Posted January 6, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155911 Share on other sites More sharing options...
pioneerx01 Posted January 6, 2011 Author Share Posted January 6, 2011 YEES! I can not express enough how thankful I am. This is about third time people on this site have helped my with this project. You guy's are the best !!!! Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155915 Share on other sites More sharing options...
Pikachu2000 Posted January 6, 2011 Share Posted January 6, 2011 You're welcome. When can we expect to receive our checks? Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155919 Share on other sites More sharing options...
PFMaBiSmAd Posted January 6, 2011 Share Posted January 6, 2011 Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155922 Share on other sites More sharing options...
pioneerx01 Posted January 6, 2011 Author Share Posted January 6, 2011 If I would not volunteer to do this for non-profit organization, I would... Even though I am way over my head on some things, I am learning so much from this about PHP. I'll see my sorry butt here soon... Quote Link to comment https://forums.phpfreaks.com/topic/223610-how-to-fix-fatal-error-call-to-undefined-function/#findComment-1155923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.