Jump to content

undefined function ???


sudsy1970

Recommended Posts

Hi,

 

bit of a php and MySql and not sure which is causing the problem so forgive me if this is not the correct forum.

 

trying to write a script that will email a username (hopefully password too later on) if a user has forgotten thier details.  The DB holds the email address, so i have tried to post the email and create a function to do the email, however i get the following message

Fatal error: Call to undefined function mail_username() in C:\xampp\htdocs\Cosford\forgot.php  on line 16

 

Any one give some clues, as i thought that i had defined the function earlier in my code. also do i have to use two pages for this or can it all go into the same page ?

 

Code listed below:

 

Forgot.php

<?php

     // connect to the database

        $dbServer = mysql_connect("localhost", "web", "LzAUScXJ4tfAUvcm");
        mysql_select_db("cosfordfc", $dbServer);






   # If an email address has been provided by the customer, email the Username to it

   if (isset($_POST['email'])) {
  mail_username();

   }
   else {
   	  include "forgotuser.php";
   }



   ?>



   # Function for mailing the Username for a given email address

   function mail_username() {

   # Get the provided email address

   $Email = $_POST['email'];

   # Build the SQL for selecting the Username based on email address supplied

   $sql = "SELECT user FROM users WHERE email = '$Email'";

   $result = mysql_query($sql);

   $row = mysql_fetch_array($result, MYSQL_NUM);

   # Row will contain the Username 
   
   # Compose an email for the customer
   
     $body = "Username Request\r\n";
     $body .= "\r\n";
     $body .= "This is an automated response to a username request:\r\n";
     $body .= "\r\n";
     $body .= "Username : $row[0] \r\n";
     $body .= "\r\n";
     $body .= "Kind Regards, \r\n";
     $body .= "\r\n";
     $body .= "AIM HIGH DRIVING School\r\n";
     $body .= "\r\n";


     $headers .= 'From: AIM HIGH DRIVING School <[email protected]>';
     $subject = 'Confirmation of Username';

    # Send the email to the customer containing Username information

     ini_set('display_errors', 0);

     mail($Email, $subject, $body, $headers);


     ini_set('display_errors', 1);
     
     echo 'Check your inbox for your username!';
?>

 

forgotuser.php

<?php

include "template.php"

?>

<h1>Please enter the following details</h1>
  <FORM action="forgot.php" method="post">
          <p> Enter your email address</p>
          <p><INPUT type="text" name="email"></p>
          <p> <INPUT type="submit" value="Submit"></p> 
          </FORM>

 

Link to comment
https://forums.phpfreaks.com/topic/205359-undefined-function/
Share on other sites

Cheers i can see that, and after i had aslo missed a curly bracket.

 

Now i have

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Cosford\forgot.php on line 43

 

 

that line to me doesn't have any boolean

 

$row = mysql_fetch_array($result, MYSQL_NUM);

 

Does this mean that no result is being returned ? if so there is a serious problem as the table definatley contains the email address.

Link to comment
https://forums.phpfreaks.com/topic/205359-undefined-function/#findComment-1074748
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.