Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Uncaught Error: Call to undefined function

Hi everyone, i am currently making a login/registration system and i'm making a send_email function so the user can recover their password.

The code is:

function recover_password() {

if($_SERVER['REQUEST_METHOD'] == "POST") {

    if(isset($_SESSION['token']) && $_POST['token'] === $_SESSION['token']) {

          $email = $_POST['email'];

          if(email_exists($email)) {

              $validation = md5($email, microtime());

              $subject = "Please reset your password";

              $message = "Hi here is your password reset code: {$validation}

              Click here to reset your password http://localhost/login/code.php?email=$email&code=$code

               ";

              $headers = "From: noreply@zestymemes.com";

              send_email($email, $subject, $message, $headers);

          }

     }

  }

Now the error i'm getting when i'm posting the submission to send me the email is:

Fatal error: Uncaught Error: Call to undefined function email_exists() in /Applications/XAMPP/xamppfiles/htdocs/login/functions/functions.php:424 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/login/recover.php(11): recover_password() #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/login/functions/functions.php on line 424

I searched around but with no help really. What could i have done wrong? The weird thing is longer up in my code i use the email_exists() and that works totally fine, but not this code.

andi mitre
andi mitre
Treehouse Guest Teacher

either your function is out of scope or it has not been created

andi . the email_exists function has been created as i'm using it longer up in my code.

andi what do you mean with 'out of scope' ?

andi mitre
andi mitre
Treehouse Guest Teacher

meaning that the email_exists() function could be within a different class. read more about scope here (http://stackoverflow.com/questions/5955446/php-function-scope)