View Full Version : My function isn't getting called.

05-31-2007, 01:59 PM
I promise not to ask too many more stupid questions. But Im stuck here and need someone to help me find the way.

When the user clicks on "go" the index is reloaded and this code is executed. I'm getting the prompt "calling validate".

The form

<form action="" method="POST">
<table id="loginForm">
<tr class="smallText">
<td>User ID:</td>
<td><input type="input" name="userID" size="15" class="smallText" /></td>
<tr class="smallText">
<td><input type="password" name="password" size="15" class="smallText" /></td>
<tr><td><input type="hidden" name="menuaction" value="login" /></td></tr>
<tr><td><input type="submit" name="submit" value="Go"></td></tr>

if (isset($_POST['menuaction'])){
switch ($_POST['menuaction']){
case 'login':
echo "Calling validate";
if (validateUser($_POST['userID'], md5($_POST['password'])))
echo "if passed";
echo "You Screwed up!";
case 'Register':
} //end switch
}//end if

The validate function looks like this:

function validateUser($usr, $pwd){
echo "calling openDB";
if (!empty($db)){
echo "open successful";
$qry="SELECT * FROM Users WHERE UserName=".$usr." AND ".$pwd."=UserPswd";
if ($result = mysql_query($qry))
return True;
echo "open failed"
die ("Error in query: $query. ".mysql_error());
return False;

Note that I also have prompts there. When this runs all I get is a blank screen and the one "Calling Validate" prompt.

The function is in functions.php and the index.php has the include to include the function page. I did have it set to require_once and changed it to include just to make sure I had that right. Is it my function call?

I think it's just a syntax thing. I'm still learning so it could be any stupid oversight. Your input is appreciated.

05-31-2007, 03:16 PM
YOu should turn on error reporting and good practice is to die out all your queries whether your a pro or a beginner.

this is your problem

$qry="SELECT * FROM Users WHERE UserName=".$usr." AND ".$pwd."=UserPswd";

You have the variable $pwd as the field name and the field name as the value. If you would have die'd that out, it would have told you. :)

05-31-2007, 04:53 PM
Yeah, I caught that right after I posted and fixed it with:

$qry="SELECT * FROM Users WHERE UserName=".$usr." AND UserPswd=".$pwd;

I still have the same problem. As far as turning on error reporting; is that done in the php.ini file?

05-31-2007, 04:56 PM
I'm assuming that username and password are text fields. Try this:

$qry="SELECT * FROM Users WHERE UserName='".$usr."' AND UserPswd='".$pwd . "'";

05-31-2007, 05:26 PM
I found the problem. It was stupid. Wrong DB name.
Also I found this in a book.

ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);

Thanks for the help.

05-31-2007, 06:23 PM
I'd recommend this.

error_reporting(E_ALL | E_NOTICE);

If you are still developing/debugging it, you'll want to include notices.

05-31-2007, 06:30 PM

E_ALL includes everything except E_STRICT

05-31-2007, 06:49 PM
For some reason I remember it being E_NOTICE. I stand corrected.

error_reporting(E_ALL | E_STRICT);

05-31-2007, 10:01 PM
error_reporting(E_ALL | E_STRICT);

Throws this:
Notice: Use of undefined constant E_STRICT - assumed 'E_STRICT' in c:\phpdev5\www\alaskanerrands\index.php on line 3