returning ResultSet into different page
Posted: Thu Jun 03, 2010 6:15 am
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.
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;
}
?>