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

"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.

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

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.

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.