I have moved from MySql to Sqlsrv and was updating my PHP. I'm not that versed in PHP and definitely not Sqlsrv, but have been using the PHP: SQLSRV Manual. Here is my PHP code:
<?php
include '../includes/dbconfig.php';
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from Form
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
//extract($_POST);
$sql="SELECT username FROM dbname WHERE username='$myusername' and userpassword='$mypassword'";
$result=sqlsrv_query($conn,$sql) or die(print_r(sqlsrv_errors(),true));
if ($result) {
$rows = sqlsrv_has_rows( $result );
if ($rows === true)
echo "There are rows. <br />";
{
$_SESSION['login_user']=$myusername;
header("Location: orderform.php");
}
else
{ $error="Your Login Name or Password is invalid"; }
}
}
?>
The code that is causing the problem is:
{
$_SESSION['login_user']=$myusername;
header("Location: orderform.php");
}
If I comment those lines out, the login form comes up and if I put a correct username and password, I get the "There are rows" comment. If not, I get "Your Login Name or Password is invalid". Once I put those lines back in, the login screen will not even come up. I don't get an error or anything. I've been working on this for 2 days...can someone help me out?