Create register for ASP.Net Web App

From TRCCompSci - AQA Computer Science
Revision as of 14:27, 19 October 2024 by Admin (talk | contribs) (Created page with " <syntaxhighlight lang=c#> public IActionResult OnPost() { User temp = new User(); string username = Request.Form["user"]; string pass1 = Request.Form["password...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
public IActionResult OnPost()
{
     User temp = new User();
     string username = Request.Form["user"];
     string pass1 = Request.Form["password1"];
     string pass2 = Request.Form["password2"];

     temp.status = Convert.ToInt32(Request.Form["status"]);

     using var connection = GetConnection;

     connection.Open();
     string sql = "insert into test values(@p1, @p2, @p3);";
     using var Command = new MySqlCommand(sql, connection);
     Command.Parameters.AddWithValue("@p1", temp.username);
     Command.Parameters.AddWithValue("@p2", temp.password);
     Command.Parameters.AddWithValue("@p3", temp.status);

     Command.ExecuteNonQuery();
     connection.Close();
	
     users.Add(temp);

     return Page();
}