I develop the signup page(
signup.aspx
) and also login page(
login.aspx
) in signup page user also upload their picture please modify the login code in the way that when user login only image upload by that user display on next page for ex(infor.aspx) i simply want logic in
login.cs
code
My database table name is
Table1
ID int
Eamil varchar(20) primary key
password varchar(20)
confirmpassword varchar(20)
Name varchar(20)
country varchar(20)
Gender varchar(20)
year varchar(20)
month varchar(20)
date varchar(20)
Description varchar(20)
PictureFile image
login.cs
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\WebSite4\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
string query = "Select Password from Table1 Where Email='" + TextBox2.Text + "'";
SqlCommand com = new SqlCommand(query, con);
SqlDataReader rd;
rd = com.ExecuteReader();
while (rd.Read())
{
s = rd[0].ToString();
}
con.Close();
if (s == TextBox1.Text)
{
Session["Email"] = TextBox2.Text;
Response.Redirect("information.aspx");
}
else
{
Response.Write("<script language='javascript'>alert( 'Invalid password or Email ' )</script>");
}
Signup.cs
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con1 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\WebSite4\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
con1.Open();
SqlCommand sc = new SqlCommand("Select Email from Table1", con1);
SqlDataReader rd;
rd = sc.ExecuteReader();
while (rd.Read())
{
if (rd["Email"].ToString().Equals(TextBoxEmail.Text))
{
Response.Write("<script language='javascript'>alert( 'Already Exsist ' )</script>");
k = 1;
}
}
con1.Close();
if (k == 0)
{
string fileName = FileUpload1.PostedFile.FileName;
int fileLength = FileUpload1.PostedFile.ContentLength;
byte[] imageBytes = new byte[fileLength];
FileUpload1.PostedFile.InputStream.Read(imageBytes, 0, fileLength);
string connStr = ConfigurationManager.AppSettings["ConnStr"].ToString();
using (SqlConnection conn = new SqlConnection(connStr))
{
string query1 = "insert into Table1(Email,Password,confirmPassword,Name,Country,Gender,Year,Date,Month,Description,PictureFile)values('" + TextBoxEmail.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBoxName.Text + "','" + TextBox1.Text + "','" + DropDownList1.Text + "','" + DropDownList4.Text + "','" + DropDownList2.Text + "','" + DropDownList3.Text + "','" + TextBox2.Text + "',@pictureFile)";
SqlParameter[] prms = new SqlParameter[1];
prms[0] = new SqlParameter("@pictureFile", SqlDbType.Image);
prms[0].Value = imageBytes;
using (SqlCommand cmd = new SqlCommand(query1, conn))
{
cmd.Parameters.AddRange(prms);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
Response.Redirect("Login.aspx");
}