Note that there are some explanatory texts on larger screens.

plurals
  1. POImplement a session and retrieve from mysql table?
    text
    copied!<p>How do I implement this session: (UserID is part of the login table) </p> <pre><code>Session["UserID"]="usrName"; </code></pre> <p>Into this code?</p> <pre><code>using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Odbc; using System.Data.SqlClient; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Login1.Authenticate += Login1_Authenticate; } protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { //database connection string OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; User=x; Password=x; OPTION=3;"); cn.Open(); OdbcCommand cmd = new OdbcCommand("Select * from User where username=? and password=?", cn); //Select the username and password from mysql database in login table 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; //use asp login control to check username and password cmd.Parameters.Add(new OdbcCommand("@UserID", 'id.int')); 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(); int id = cmd.Parameters["@UserID"].Value; Session["UserID"]="usrName"; if (dr.Read()) { e.Authenticated = true; Response.Redirect("UserProfileWall.aspx"); // Event Authenticate is true forward to user profile } } } </code></pre> <p>I need to be able to retrieve the correct UserID when some one inputs there username and password upon login and then some how retrieve it on a new page something like this to retireve it but unsure?</p> <pre><code>string usrName = Convert.ToString(Session["UserID"]); </code></pre> <p>I just dont know how to add the first part, the session into my login code so I can some how store the UserID in my session but also retrieve the correct UserID from the submitted data that takes from my mysql login table.</p>
 

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