Page 1 of 1

Login and Register Form (MYSQL)

Posted: Sat Mar 12, 2011 9:42 pm
by MrAlicard
Free MYSQL Server: http://www.db4free.net
MYSQL Connector download: http://www.mysql.com/downloads/connector/net/
And import the MYSQL Connector.
Go to Project-->Add Reference...---->.NET tab--->Click MySql.Data--->OK

OK to import the MySql.Data.
Code: Select all
Imports MySql.Data.MySqlClient
Login Form
Code: Select all
Dim conn As MySqlConnection
        'connect to DB
        conn = New MySqlConnection()
        conn.ConnectionString = "server=82.103.129.94; user id=dbusername; password=dbpassword; database=db"
        'see if connection failed.
        Try
            conn.Open()
        Catch myerror As MySqlException
            MsgBox("Error connecting to database!")
        End Try
        'sql query
        Dim myAdapter As New MySqlDataAdapter

        Dim sqlquery = "SELECT * FROM user WHERE username='" + TextBox1.Text + "' AND password= '" + TextBox2.Text + "'"
        Dim myCommand As New MySqlCommand()
        myCommand.Connection = conn
        myCommand.CommandText = sqlquery
        'start query
        myAdapter.SelectCommand = myCommand
        Dim myData As MySqlDataReader
        myData = myCommand.ExecuteReader()
        'see if user exists
        If myData.HasRows = 0 Then
            MsgBox("Invalid username and/or password!")
Register Form
Code: Select all
Dim conn As MySqlConnection
                'connect to DB
                conn = New MySqlConnection()
                conn.ConnectionString = "server=82.103.129.94; user id=dbusername; password=dbpassword; database=db"
                'see if connection failed.
                Try
                    conn.Open()
                Catch myerror As MySqlException
                    MsgBox("Error connecting to database!")
                End Try
                'sql query
                Dim myAdapter As New MySqlDataAdapter

                Dim sqlquery = "SELECT * FROM user WHERE username='" + TextBox1.Text + "'"
                Dim myCommand As New MySqlCommand()
                myCommand.Connection = conn
                myCommand.CommandText = sqlquery
                'start query
                myAdapter.SelectCommand = myCommand
                Dim myData As MySqlDataReader
                myData = myCommand.ExecuteReader()
                'see if user exists
                If myData.HasRows = 0 Then

                    conn.Close()
                    conn.Open()
                    Dim registerfinal As New MySqlDataAdapter

                    sqlquery = "INSERT INTO user (username, password, email) VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')"
                    myCommand.Connection = conn
                    myCommand.CommandText = sqlquery
                    'start query
                    registerfinal.SelectCommand = myCommand
                    myData = myCommand.ExecuteReader
                    MsgBox("Thank you for registering!")
MYSQL table and field requirement:
-Table: user
- Fields: username, password, email

Re: Login and Register Form (MYSQL)

Posted: Sat May 21, 2011 8:17 pm
by zachman61
doesn't work for me.

Re: Login and Register Form (MYSQL)

Posted: Sat May 21, 2011 8:22 pm
by Codex
zachman61 wrote:
doesn't work for me.
Maybe you can be more specific ?

Re: Login and Register Form (MYSQL)

Posted: Fri Jun 24, 2011 6:18 pm
by TekTabanca
Thanks

Re: Login and Register Form (MYSQL)

Posted: Fri Jun 24, 2011 6:59 pm
by Agust1337
Spam Much? Please read the rules before writing useless posts...

Re: Login and Register Form (MYSQL)

Posted: Tue Aug 30, 2011 9:43 pm
by Napster1488
I have made a Website on http://www.000webhost.com
And registered there a mysql,
but everytime i try to connect and save into my mysql database with this code i get a error.
Where do i get the Informations for server and user id ?!
i tryd using the website ip as server and my servername "server23.000webhost.com" and also the mysql servername ?!

Re: Login and Register Form (MYSQL)

Posted: Tue Aug 30, 2011 10:38 pm
by Agust1337
Whats the error exception?

Re: Login and Register Form (MYSQL)

Posted: Tue Aug 30, 2011 10:57 pm
by Napster1488
Agust1337 wrote:
Whats the error exception?
I just made a Database on http://www.db4free.net
Everything works now.

Re: Login and Register Form (MYSQL)

Posted: Mon Sep 05, 2011 3:21 pm
by Kobra1984
cool!

Re: Login and Register Form (MYSQL)

Posted: Tue Sep 06, 2011 7:18 pm
by rocky4126
000webhost doesn't have support for remote MySQL connections, that's why they fail.