Jump to content

Return Resultset into different PHP page


khhalid

Recommended Posts

Hi guys,

I am using PHP 5.25 with SQL Server.  I have install 'SQL server driver for PHP'.

 

I am building login page with SQL Server DB authentication.

So, my login.php pass SQL query to a function named 'querySQLServer' in functions.php.

 

I can see the resultset within functions.php but when return to login.php, resultset is empty.

 

<?php 
//login.php

include_once 'functions.php';


echo "<h3>Bookmaker Log in</h3>";
$error = $user = $pass = "";

if (isset($_POST['user']))
	{

		$user = $_POST['user'];	
		$pass = $_POST['pass'];	
		$query = "exec fodSelectLogin '$user' , '$pass'";		

		$result = querySqlServer($query);	

//** this $result is empty and fail the authentication**

		if (sqlsrv_has_rows($result) === false )		
		{
			$error = "Username/Password invalid<br />";
		}
		else			
		{ 				
			$_SESSION['user'] = $user;
			$_SESSION['pass'] = $pass;			
			die("You are now logged in. Please
			<a href='members.php?view=$user'>click here</a>.");		
		}
	}


  

echo <<<_END
<form method='post' action='login.php'>$error
Username <input type='text' maxlength='16' name='user'
value='$user' /><br />
Password <input type='password' maxlength='16' name='pass'
value='$pass' /><br />
<input type='submit' value='Login' />
</form>
_END;
?>

<?php 
//functions.php
define("DB_SERVER", "NDRDT034\SQLEXPRESS");
define("DB_USER", "northdoor");
define("DB_PASS", "N0rthd00r");
define("DB_NAME", "LevyDataDevelopment");

$appname = 	"HBLB - FOD";

function querySqlServer($query)
{

//connection details	
$connectionInfo = array("Database" 	=> DB_NAME ,
						"UID" 		=> DB_USER,
						"PWD"		=> DB_PASS);
//connecting
$dbconn = sqlsrv_connect(DB_SERVER, $connectionInfo)
		or die("Couldn't connect to SQL Server on DB_SERVER");

$resultSet = sqlsrv_query($dbconn, $query);

if( $result === false )
{
	echo "Error in executing query.</br>";
	die( print_r( sqlsrv_errors(), true));
}	

return $resultSet;	
}

?>


thanks for your reply,

sorry, it was typing mistake when I was trying different codes.

But even I have change the variable back to $resultSet, it is empty in login.php.

 

Have had a chance to pass resultSet between PHP pages?

 

Many thanks for your time,

K

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.