returning ResultSet into different page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
khhalid
Forum Newbie
Posts: 7
Joined: Tue Apr 20, 2010 4:45 pm

returning ResultSet into different page

Post by khhalid »

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.

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

Code: Select all

<?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;	
}

?>

User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: returning ResultSet into different page

Post by markusn00b »

At the top of login.php, turn on error reporting.

Code: Select all

error_reporting(-1);
Post Reply