Callinng a function after submit

Discussion in 'PHP' started by cris02, Oct 1, 2010.

  1. #1
    Hello I have a login form I would like to put the login process in a function. here's my code
    
    //this code works
    if(isset($_POST['logmein'])){
    	$uname = mysql_real_escape_string($_POST['username']);
    	$pass = mysql_real_escape_string($_POST['password']);
    	
            $rrr = $db->select("SELECT * FROM tbluser WHERE uname = '$uname' and pass = '$pass' LIMIT 1");
    	$count=mysql_num_rows($rrr);
    	if($count == 0){
    		$alert_msg="Invalid username/password.";
    
    	}else{
    		$alert_msg="Correct Login";
    	}
    }
    
    PHP:
    But I want to change that code into this:
    
    //function.php
    function validateUser($uname,$pass){
           ...query mysql for processing....
    }
    
    //loginform.php
    include('function.php');
    if(isset($_POST['logmein'])){
       //call the function
       validateUser($_POST['username'],$_POST['password']);
    }
    
    PHP:
    Any suggestion? Please help.. Thanks
     
    cris02, Oct 1, 2010 IP