khhalid Posted June 3, 2010 Share Posted June 3, 2010 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; } ?> Link to comment https://forums.phpfreaks.com/topic/203733-return-resultset-into-different-php-page/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 3, 2010 Share Posted June 3, 2010 I can see the resultset within functions.php How do you know that? Your querySqlServer() function code is setting a variable named $resultSet, but it is testing a variable named $result. Link to comment https://forums.phpfreaks.com/topic/203733-return-resultset-into-different-php-page/#findComment-1067158 Share on other sites More sharing options...
khhalid Posted June 3, 2010 Author Share Posted June 3, 2010 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 Link to comment https://forums.phpfreaks.com/topic/203733-return-resultset-into-different-php-page/#findComment-1067160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.