-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusersignup.aspx.cs
More file actions
91 lines (83 loc) · 2.98 KB
/
usersignup.aspx.cs
File metadata and controls
91 lines (83 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace RegisterLogin
{
public partial class usersignup : System.Web.UI.Page
{
string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
//sign up button click event
protected void Button1_Click(object sender, EventArgs e)
{
if(checkUserExists())
{
Response.Write("<script>alert('User already exists! Try another email');</script>");
}
else
{
signUpNewUser();
}
}
bool checkUserExists()
{
try
{
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("select * from user_info where email='"+TextBox3.Text.Trim()+"';", con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
Response.Write("<script>alert(' " + ex.Message + "');</script>");
return false;
}
}
void signUpNewUser()
{
try
{
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("insert into user_info(fullname,dateofbirth,email,contact,password) values (@fullname,@dateofbirth,@email,@contact,@password)", con);
cmd.Parameters.AddWithValue("@fullname", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@dateofbirth", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@email", TextBox3.Text.Trim());
cmd.Parameters.AddWithValue("@contact", TextBox4.Text.Trim());
cmd.Parameters.AddWithValue("@password", TextBox5.Text.Trim());
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('Sign Up Succesful. Go to user login page');</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert(' " + ex.Message + "');</script>");
}
}
}
}