Jump to content

writing a simple function


bruckerrlb

Recommended Posts

I'm writing my first function here and after reading and testing with easy things, I'm trying to do something not so hard, but am having a hard time finding results. I have my functions page with a function declared like the following:

function test_user_input($username) {
		$stmt = mssql_init('pgetuserid');
		mssql_bind($stmt, "@loginuid", $username, SQLVARCHAR); 

		$result = mssql_execute($stmt);

		//get the user id to store in session and or insert into new db
		$row = mssql_fetch_array($result); 

	//get the loginid
	$loginid = $row['loginid'];
	$loginuid = $row['loginuid'];
	//echo "First result $loginid";
	return $loginid;
	return $loginuid;
	return $row;
	return $result;

	}

Then, I call the function as such

$username=$_POST['myusername']; 
test_user_input($username);

The function initiates, binds and executes a ms sql stored procedure which isn't the problem, whenever I take out the function and place it directly in the page it works fine, but trying to declare it in a function, it's failing at the count part

$count = mssql_num_rows($result);
//if user does exist:
if($count==1) {

 

Any ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/199900-writing-a-simple-function/
Share on other sites

Functions can only return 1 value. I'm not exactly sure what your trying to achieve, but you may be best to simply return $result. be aware, that you also need to assign the returning data to a variable outside your function if you plan on using it. eg;

 

$result = test_user_input('foo');
$count = mssql_num_rows($result);
if($count==1) {
  // do something
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.