Note that there are some explanatory texts on larger screens.

plurals
  1. POteaching about sessions?
    primarykey
    data
    text
    <p>Can any one teach me how to use sessions? I have a login page which refers to mysql db table named User which includes UserID="variable number", username and password. Id like to be able to store the userid in a session so I can call it inside the users profile when he logs in. </p> <p>How is this done? Any relevant coding and placement of specific coding would be helpful as Im just not picking it up at all. Does it go inside the code behind (.cs file) or is it held in the html of the aspx page? or both and how? How does the session work across multiple inner pages (once logged in you can broswe more than one page related to your own profile) </p> <pre><code> using System.Data.Odbc; partial class login : System.Web.UI.Page { protected void Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e) { OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=mydb; User=root;Password=;"); cn.Open(); OdbcCommand cmd = new OdbcCommand("Select * from login where username=? and password=?", cn); //Add parameters to get the username and password cmd.Parameters.Add("@username", OdbcType.VarChar); cmd.Parameters["@username"].Value = this.Login1.UserName; cmd.Parameters.Add("@password", OdbcType.VarChar); cmd.Parameters["@password"].Value = this.Login1.Password; OdbcDataReader dr = default(OdbcDataReader); // Initialise a reader to read the rows from the login table. // If row exists, the login is successful dr = cmd.ExecuteReader(); if (dr.HasRows) { e.Authenticated = true; // Event Authenticate is true } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload