Help needed with my code (Function)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

Help needed with my code (Function)

Post by gimpact »

Hello,
I have no idea why this is not working. I read some tutorials and all seems to point in the direction that, this code should work.

Code: Select all

 
if(ISSET($_REQUEST['submit'])){ 
// Get username and password from the form 
$email = trim($_REQUEST['email']); 
$password = md5(trim($_REQUEST['password'])); 
$author = $_REQUEST['checkbox'];
 
// When the user is student 
if($author == null){ 
checkStudentAccount($email,$password); 
} 
// Not yet implemented 
if($author == 'teacher'){ 
print "Teacher"; 
die(); 
}
 
function checkStudentAccount($email,$password){ 
... 
}
 
The error that I am getting
Fatal error: Call to undefined function: checkstudentaccount()

Any help will be greatly appreciated, thank you.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Help needed with my code (Function)

Post by Mirge »

Don't know if that's your actual code... but if it is, PLEASE start indenting better. Here is better indenting, with your code fixed:

Code: Select all

 
<?php
if(isset($_REQUEST['submit'])) {
    // Get username and password from the form
    $email = trim($_REQUEST['email']);
    $password = md5(trim($_REQUEST['password']));
    $author = $_REQUEST['checkbox'];
 
    // When the user is student
    if($author == null) {
        checkStudentAccount($email,$password);
    }
    
    // Not yet implemented
    if($author == 'teacher') {
        print "Teacher";
        die();
    }
} // [b]<--- THIS CLOSING BRACE WAS MISSING.[/b]
 
 function checkStudentAccount($email,$password){
        return true;
 }
 
?>
 
If you had indented properly, you would have been more likely to notice that closing brace error :).
gimpact
Forum Commoner
Posts: 65
Joined: Tue Jun 16, 2009 11:08 pm

Re: Help needed with my code (Function)

Post by gimpact »

Thank you,

I copied that code from netbeans, so i guess it is like that.

"return true" is the thing !!!

Thank you.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Help needed with my code (Function)

Post by Mirge »

gimpact wrote:Thank you,

I copied that code from netbeans, so i guess it is like that.

"return true" is the thing !!!

Thank you.
Well you had a syntax error (missing closing brace). Now you need to replace your "return true" line with actual logic for validating a user.
Post Reply