<?php require_once('include/connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
mysql_select_db($selectdb, $connect);
$query_Recordset1 = "SELECT * FROM users";
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['sname'])) {
  $sname=$_POST['sname'];
  $pass=$_POST['pass'];
  $main_page = "blog-posts.php";
  $redirectLoginFailed = "login-fail.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($selectdb, $connect);
  $LoginRS__query=sprintf("SELECT * FROM users WHERE username=%s AND pass=%s",
						  GetSQLValueString($sname, "text"), GetSQLValueString($pass, "text")); 
  $LoginRS = mysql_query($LoginRS__query, $connect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  $michael  = mysql_fetch_assoc($LoginRS);
  if ($loginFoundUser){
		header("Location: " . $main_page );
  }
  else {
    header("Location: ". $redirectLoginFailed );
  }
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login to Website Control Panel</title>
<style type="text/css">
.loginform{width:250px;margin-left:auto;margin-right:auto;height:auto;margin-top:10%;}
</style>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="loginform">
<div class="panel radius">
<form ACTION="<?php echo $loginFormAction; ?>" name="form1" method="POST">
<p>
<label for="uname"><strong><br>
<br>
User Name</strong></label>
<input type="text" name="sname" id="sname">
<label for="pass"><strong>Password</strong></label>
<input type="password" name="pass" id="pass">
<input type="submit" name="log" id="log" value="Sign in">
</p>
</form>
</div>
</div>
<link rel='Stylesheet' property='stylesheet' href='style.css' />

</body>
</html>