Forum Moderators: coopster

Message Too Old, No Replies

Help with code

         

impact

12:59 pm on Sep 25, 2009 (gmt 0)

10+ Year Member



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.

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.

bkeep

7:03 pm on Sep 25, 2009 (gmt 0)

10+ Year Member



The error you are getting should tell you what is wrong.

{quote}Fatal error: Call to undefined function: checkstudentaccount(){/quote}

Your checkstudentaccount() function is not accessible by your page either create the function on that page or include the page with the function.

impact

5:21 am on Sep 26, 2009 (gmt 0)

10+ Year Member



Thanks for replying.

Yes that function is on the same page. So, I was wondering where I am wrong exactly.

However, I rewrote that function in another page and included it yesterday. It is working now.

impact

5:28 am on Sep 26, 2009 (gmt 0)

10+ Year Member



Okie, I got what was missing in my code

"RETURN TRUE"

I should have this at the end of all functions.

rocknbil

4:49 pm on Sep 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, return something- that is what a function does, returns a value. I was wondering by the wireframe code if it was just an empty function. Although I was really confused by the lower case error response, wondering if PHP was doing that.

It might be a better approach to do something like this:

if($author == null){
$isValid = checkStudentAccount($email,$password);
}

function checkStudentAccount($email,$password) {
$validated=0;
// Do some stuff to set to 1 if valid
return $validated;
}

impact

5:25 pm on Sep 26, 2009 (gmt 0)

10+ Year Member



Thanks,
Well, crux of the problem is that, my function sends an email, appends user data into database and redirects user to login page. So I have nothing to return from the function.

Now I can split the work of the function. I can make it send email and append database and return true. As mentioned by you, I can then store the return value of the function in a variable and depending up on the data in the variable I can redirect user.