Click here to Skip to main content
15,508,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have searched code for connecting my c#.net project with phpmy sql db..main purpose is to authenticate my login..Usernam and password is saved in a tablein php mysql..I want the project to chek with that saved credentials and enter into another page if all ok..

I have got many codings..but exceptions are raised in most of that..I have designed 2 textboxes for username and password entry and a login button.. Please help me...I want c#.net code for this...if possible please do mail me how I can do this...

Looking ahead to hear from you..
my id [email removed]

[edit(zorgoz): email removed in your interest]
Posted
Updated 3-Sep-12 20:03pm
v3
Comments
Zoltán Zörgő 31-Aug-12 13:21pm    
What has this to do with PHP? You either connect to the database from C# or from PHP, or both, but not from C# to PHP. Please improve your question, and remove irrelevant parts!

Not taking into consideration the PHP related parts, since it has no importance how you filled the table, here is a tutorial about how to use MySQL from c#: http://zetcode.com/db/mysqlcsharptutorial/[^]. But first, you have to install the MySQL connector: http://www.mysql.com/downloads/connector/net/[^], and reference it from your project. And here is how you have to specify your connection string to the MySQL DB server: http://connectionstrings.com/mysql[^]. Be aware, that if it is outside your intranet, and you have no control over the firewall protecting it, you will be most likely not able to connect to the database.
 
Share this answer
 
Comments
Member 9397350 31-Aug-12 13:38pm    
thanks zoltan..but when ---.open() is given in the code..when it is executing exception is occuring...so..is it necessary to give it inside a try...catch??
Zoltán Zörgő 31-Aug-12 13:39pm    
First of all, what is the exception?
Member 9397350 31-Aug-12 13:46pm    
THIS IS THE CODING FOR MY DESIGN..
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void Login_Load(object sender, EventArgs e)
{

}
private void button1_Click(object sender, EventArgs e)
{
I WANT TO AUTHENTICATE MY LOGIN FORM HERE BY COMPARING MY DATABASE..
}


}
}
Zoltán Zörgő 31-Aug-12 14:06pm    
You wrote, that .Open() throws an exception. I would like to see that part, and your connection string.
I am working in an environment where out database is MySQL and we access via C# & ASP.Net front end. I am providing you few codes hoping that you will understand.

I assume that you already have the necessary compatible MySQL deliverables(dlls) files for your .Net application.

C#
using MySql;
using MySql.Data;
using MySql.Data.MySqlClient;
  
private void button2_Click(object sender, EventArgs e)
{

    string str_user_entered_id=txtuser.text;
    string str_user_entered_pass=txtpass.text;

     //Establishing the MySQL Connection
    MySqlConnection conn = new MySqlConnection("Database=zzzz_live;Data Source=eu;User Id=yyyy;Password=xxxx");
    
    //Open the connection
    conn.Open();
    
    MySqlCommand comm;
    MySqlDataReader reader;
    
    //Generating the query to fetch the contact details
    qry = "SELECT ref_no,user_ID,pass FROM `zzzz_live`.`table_name`";
    
    comm = new MySqlCommand(qry, conn);
    reader = comm.ExecuteReader();
    
    while (reader.Read())
    {
    string user_id=reader[1];
    string user_pass=reader[2];
    
    //Check/ validate the user name and password with the user entered values here
    if(user_id.equal(str_user_entered_id) && user_pass.equals(str_user_entered_pass))
        {
            //Authentication success
        }
    }
}


Try this code.. If you get any errors please comment here.

Thanks
 
Share this answer
 
Comments
Member 9397350 5-Sep-12 11:58am    
Thanks Swinkaran...But its not working in my project..i dont know how to xplain you my design and coding...
Swinkaran 5-Sep-12 20:30pm    
When you say it is not working, what is the error? Is there any error message? Could you provide me the code? The question you asked here is very basic.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900