Calling a function within a function

Discussion in 'PHP' started by j_o, Jul 18, 2012.

  1. #1
    Hi everyone I have a control panel for a website that I run. Each task that can be run by the control panel is a function. Recently I have added a wiki to the site and and trying to merge the database interactions together. For example if a user changes the password on the site it will go into the database and update their wiki password. I am able to do this if I do not use a function but since this action will be called in a few different places I would like to make it a function.

    When I call the function this is the error i get:
    Where line 165 is where my close php, ?>, is.

    So here is what i have:
    
    function ChangePassword(){
    		if(isset($_POST['ChangePassSubmit'])){
    				...
    				...
    				A bunch of code doing other stuff that does not relate
    				...
    				...
                                    require_once('includes/MediaWikiCustomFunctions.php'); //this loads the function if it hasnt already been used
        			       $this->UpdateMWPass($email, $wiki_newpass, "wiki_"); //Calling the function
                   }
    }
    
    PHP:
    Here is the definition of the UpdateMWPass code. The code inside the declaration is not giving me error so I believe that it works.

    
    function UpdateMWPass($email, $NewPass, $wiki_prefix = NULL){
    	$sql = mysql_query("SELECT * FROM `wiki_user` WHERE `user_email`='{$email}' ");
    	confirm_query($sql);
    	
    	if(mysql_num_rows($sql) == 1){
    		$row = mysql_fetch_array($sql);
    		$wiki_id = $row['user_id'];
    		//Last we update the password. 
    		
    		$wiki_Fullsalt = md5(dechex(mt_rand()) . dechex(mt_rand())); //Generates a 32 character md5 string -> We need 8 characters
    		$wiki_salt = NULL; //Initially no salt is set
    		//Here we are choosing 8 random charactors from the 32 character string to be our salt
    		for($i=0; $i<8;$i++){
    			$randomChar = $wiki_Fullsalt[rand(0, strlen($wiki_Fullsalt)-1)];
    			$wiki_salt .= $randomChar;
    		}
    		//Now that we have a salt we can create the password in the proper format
    		$user_password = ':B:' . $wiki_salt . ':' . md5( $wiki_salt . '-' . md5( $NewPass ) );
    		
    		$pass_query = mysql_query("UPDATE {$wiki_prefix}user SET user_password = '{$user_password}' WHERE user_id = {$wiki_id}");
    		confirm_query($pass_query);
    }
    
    PHP:
    Thanks in advance for any help.
     
    Solved! View solution.
    Last edited: Jul 18, 2012
    j_o, Jul 18, 2012 IP
  2. #2
    It is possible that you forgot to close a loop or a condition (missing curly bracket - "}").
     
    Devtard, Jul 19, 2012 IP
    j_o likes this.
  3. j_o

    j_o Well-Known Member

    Messages:
    516
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    113
    #3
    Well I don't feel to smart right now. Thanks, guess I had just been staring at it for to long.
     
    j_o, Jul 19, 2012 IP