0

Hi

I am trying to get this function to work but having issues

// check that policy number not entered on the DB if no policy is entered skip Mysql query	
	function validatePolicyNumber($PolicyNumber){
		//Return Session Value so user does not have to retype entry 
		return $_SESSION['PolicyNumberAdd'] = $PolicyNumber;
		
		$Connection = mysql_connect("localhost", "root", "")or die(mysql_error());
		mysql_select_db('mobility', $Connection) or die('Could not select database.');

		//if it's NOT valid
		$UniqueQuery = "SELECT $PolicyNumber FROM tblpolicies WHERE PolicyNumber='{$PolicyNumber}'";
		
		$result = mysql_query($UniqueQuery, $Connection);	
	   

		if(mysql_num_rows($result) >=1 )	
			return false;
		//if it's valid
		else
			return true;
		
        }

I tried to even use a global variable but still didnt work

// check that policy number not entered on the DB if no policy is entered skip Mysql query	
	function validatePolicyNumber($PolicyNumber){
		//Return Session Value so user does not have to retype entry 
		return $_SESSION['PolicyNumberAdd'] = $PolicyNumber;
		
                global $Connection;

		$Connection = mysql_connect("localhost", "root", "")or die(mysql_error());
		mysql_select_db('mobility', $Connection) or die('Could not select database.');

		//if it's NOT valid
		$UniqueQuery = "SELECT $PolicyNumber FROM tblpolicies WHERE PolicyNumber='{$PolicyNumber}'";
		
		$result = mysql_query($UniqueQuery, $Connection);	
	   

		if(mysql_num_rows($result) >=1 )	
			return false;
		//if it's valid
		else
			return true;
		
        }

Please assist

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by fabzster
0

"the return() statement immediately ends execution of the current function". See here
Therefore, the first line of code being executed in your function is returning the session variable and returning back to the area of code that the function was originally called from.

Edited by nonshatter: n/a

0

Ok I see now, but how do I then return both the Session and the answer?

0

you just initialize session. no need to return it. As it is a global parameter, if once we set it, we can get the value in any page.
replace your line: 4 like this:

$_SESSION['PolicyNumberAdd'] = $PolicyNumber;

Then your code works.

Goodluck.

Edited by Shanti C: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.