Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts

    My function isn't getting called.

    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
    PHP Code:
              <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>
                    <
    tr class="smallText">
                        <
    td>Password:</td>
                        <
    td><input type="password" name="password" size="15" class="smallText" /></td>
                    </
    tr>
                    <
    tr><td><input type="hidden" name="menuaction" value="login" /></td></tr>
                    <
    tr><td><input type="submit" name="submit" value="Go"></td></tr>
                    </
    table>
        </
    form


    PHP Code:
        if (isset($_POST['menuaction'])){
            switch (
    $_POST['menuaction']){
                   case 
    'login':
                           {
                        echo 
    "Calling validate";
                        if (
    validateUser($_POST['userID'], md5($_POST['password'])))
                           {
                        echo 
    "if passed";
                                   
    $SESSION['UserName']=$_POST['userID'];
                                   
    $SESSION['pswd']=md5($_POST['password']);
                                
    $SESSION['validated']=True;
                            }
                        else
                            {
                            
    $SESSION['validated']=False;
                            echo 
    "You Screwed up!";
                            }
                        break;    
                        }
                    case 
    'Register':
                        {
                        
    $SESSION['currentpage']="Register";
                        
    $thisPage="Register";
                        break;
                        }
                    default:
                        
    $thisPage="Home";
            } 
    //end switch
        
    }//end if 
    The validate function looks like this:
    PHP Code:
    function validateUser($usr$pwd){
        echo 
    "calling openDB";
        
    $db=openDB();
        if (!empty(
    $db)){
            echo 
    "open successful";
            
    $qry="SELECT * FROM Users WHERE UserName=".$usr." AND ".$pwd."=UserPswd";
            if (
    $result mysql_query($qry))
               {
               return 
    True;
               }
            else
               {
               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.
    Scott Stewart
    Always happy to learn from pros.

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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
    PHP Code:
    $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.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Yeah, I caught that right after I posted and fixed it with:
    PHP Code:
    $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?
    Scott Stewart
    Always happy to learn from pros.

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    I'm assuming that username and password are text fields. Try this:
    PHP Code:
    $qry="SELECT * FROM Users WHERE UserName='".$usr."' AND UserPswd='".$pwd "'"

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    I found the problem. It was stupid. Wrong DB name.
    Also I found this in a book.

    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL & ~E_NOTICE); 
    Thanks for the help.
    Scott Stewart
    Always happy to learn from pros.

  • #6
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    I'd recommend this.

    error_reporting(E_ALL | E_NOTICE);
    If you are still developing/debugging it, you'll want to include notices.
    Last edited by aedrin; 05-31-2007 at 05:51 PM.

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    error_reporting(E_ALL);

    E_ALL includes everything except E_STRICT
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #8
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    For some reason I remember it being E_NOTICE. I stand corrected.

    PHP Code:
    error_reporting(E_ALL E_STRICT); 

  • #9
    Regular Coder
    Join Date
    Nov 2002
    Posts
    567
    Thanks
    2
    Thanked 4 Times in 4 Posts
    PHP Code:
    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
    Scott Stewart
    Always happy to learn from pros.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •