Hello,
I have successfully installed PHP onto an IIS/SQL Server environment. I can get a DB connection and I can also post and display variables from one PHP page to another. I am trying to create a login script for a web application, but I am am having trouble getting any results from any select query that I write.
Here is my login.php page:
<body>
<?php ob_start(); session_start(); $username = $_POST['username']; $password = $_POST['password']; $serverName = "localhost"; $connectionInfo = array("Database"=>"Derm", "UID"=>"xxxxxxxx", "pwd"=>"xxxxxxxxx"); $conn = sqlsrv_connect( $serverName, $connectionInfo);
$query = "SELECT username, password, level, type, location FROM user_access WHERE username = '$username'"; $result = sqlsrv_query($conn, $query);
if(sqlsrv_num_rows($result) == 0) // User not found. So, redirect to login_form again. { header('Location: index.html'); } $userData = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC);
$hash = hash("sha512", $password); if($hash != $userData['password']) // Incorrect password. So, redirect to login_form again. { header('Location: index.html'); }
else{ session_regenerate_id(); $_SESSION['username'] = $userData['username']; $_SESSION['level'] = $userData['level']; $_SESSION['type'] = $userData['type']; $_SESSION['location'] = $userData['location']; session_write_close(); header('Location: main.php'); }
?>
</body>
I have checked the query many times in SQL Server management studio and it always returns the correct result using my username. However, here, the page keeps refreshing itself and never progresses to 'main.php'. Is there a way to solve this or are there any alternatives to do the same thing? I don't actually want to display the query results, rather just assign them as session variables.
Thanks