I am trying to check if user exists in my SQL Server database, but if user exists, or not, I always get the same response (redirection
to ~/korisnik/Korisnikkp. Can someone help me? Problem is compiler doesn't get username value with this @0. Do you know how to fix that? If i hardcode user with examle 'nicolas55' it works.
Thanks
if (IsPost)
{
var Username = "";
var Password = "";
Username = Request.Form["Username"];
Password = Request.Form["Password"];
if (Username != "" && Password != "")
{
var db = Database.Open("Useri");
var command = @"SELECT username FROM Users WHERE username = @Username"; //when I put here 'nikola55' it works
var result = db.QueryValue(command, Username);
if (result != null)
{
Response.Redirect("~/korisnik/Korisnikkp");
}
else
{
<script type="text/javascript">
alert("No user in database");
</script>
}
Form code:
<form method="post">
<!-- to error: add class "has-danger" -->
<label for="exampleInputEmail1">username</label>
<input type="text" value="@Username">
<label for="exampleInputPassword1">Password</label>
<a href="#" style="float:right;font-size:12px;">Forgot password?</a>
<input type="password" value="@Password">
<button type="submit" class="btn btn-primary btn-block">Sign in</button>
<div class="sign-up">
Don't have an account? <a href="/korisnik">Create One</a>
</div>
</form>