Difference between revisions of "Create register for ASP.Net Web App"
(→Creating the Page) |
(→Adding the code to handle the form) |
||
Line 17: | Line 17: | ||
{ | { | ||
string username = Request.Form["user"]; | string username = Request.Form["user"]; | ||
− | string pass1 = Request.Form[" | + | string pass1 = Request.Form["pass1"]; |
− | string pass2 = Request.Form[" | + | string pass2 = Request.Form["pass2"]; |
int status = 0; | int status = 0; | ||
Revision as of 14:34, 19 October 2024
Creating the Page
Add a new Razor Page and call it `register`.
Now add the following HTML form:
<form method="post">
Username: <input type="Text" name="user">
Password: <input type="Password" name="pass1">
Confirm: <input type="Password" name="pass2">
<input type="submit">
</form>
Adding the code to handle the form
public IActionResult OnPost()
{
string username = Request.Form["user"];
string pass1 = Request.Form["pass1"];
string pass2 = Request.Form["pass2"];
int status = 0;
if (pass1 == pass2)
{
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", username);
Command.Parameters.AddWithValue("@p2", pass1);
Command.Parameters.AddWithValue("@p3", status);
Command.ExecuteNonQuery();
connection.Close();
}
return Page();
}