I am rookie in this.
What I am trying to do is creating a simple login and register page using Html.Then I created a database in Mysql and I am using c# as my server side programming to interact with the database.(I don't waa use PHP)
Now I need your help on how to coect my Html page to the c# program.
Here is my html code.
<div class="top-row">
<div class="field-wrap">
<label>
First Name<span class="req">*</span>
</label>
<input type="text" required autocomplete="off" />
</div>
<div class="field-wrap">
<label>
Last Name<span class="req">*</span>
</label>
<input type="text"required autocomplete="off"/>
</div>
</div>
<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input type="email"required autocomplete="off"/>
</div>
<div class="field-wrap">
<label>
Set A Password<span class="req">*</span>
</label>
<input type="password"required autocomplete="off"/>
</div>
<div class="field-wrap">
<label>
Category(Doctor/Patient)<span class="req">*</span>
</label>
<input type="text"required autocomplete="off"/>
</div>
<button type="submit" class="button button-block"/>Get Started</button>
</form>
Here is my c# code
namespace dbsample { public partial class Form1 : Form { private MySqlCoection coection; private string server; private string database; private string uid; private string password;
public Form1()
{
InitializeComponent();
Initialize();
}
//Initialize values
private void Initialize()
{
server = "localhost";
database = "registerdatabase";
uid = "root";
password = "mysql";
string coectionString;
coectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
coection = new MySqlCoection(coectionString);
}
//open coection to database
private bool OpenCoection()
{
try
{
coection.Open();
retu true;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
retu false;
}
}
//Close coection
private bool CloseCoection()
{
try
{
coection.Close();
retu true;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
retu false;
}
}
//Insert statement
public void Insert()
{
if (HttpContext.Current!=null)
{
var first_name =HttpContext.Current.Request.Form["first_name"];
var last_name = HttpContext.Current.Request.Form["last_name"];
var email_address = HttpContext.Current.Request.Form ["email_address"];
var category = HttpContext.Current.Request.Form["category"];;
string query = "INSERT INTO users_db (first_name,last_name,email_address,category) VALUES("+first_name+","+last_name+","+email_address+","+category+")";
}
//open coection
if (this.OpenCoection() == true)
{
//create command and assign the query and coection from the constructor
MySqlCommand cmd = new MySqlCommand(query, coection);
//Execute command
cmd.ExecuteNonQuery();
//close coection
this.CloseCoection();
}
}
private void Form1_Load(object sender, EventArgs e)
{
Insert();
}
}
}
So, how can I coect my HTML page to c#.
Thanks in advance
