Login and Register Form (MYSQL)

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
10 posts Page 1 of 1
Contributors
User avatar
MrAlicard
VIP - Donator
VIP - Donator
Posts: 54
Joined: Thu Aug 05, 2010 4:08 pm

Login and Register Form (MYSQL)
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
You do not have the required permissions to view the files attached to this post.
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

doesn't work for me.
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: Login and Register Form (MYSQL)
Codex
zachman61 wrote:
doesn't work for me.
Maybe you can be more specific ?
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
TekTabanca
Just Registered
Just Registered
Posts: 2
Joined: Fri Jun 24, 2011 5:35 pm

Thanks
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Spam Much? Please read the rules before writing useless posts...
Top-notch casual Dating
User avatar
Napster1488
VIP - Donator
VIP - Donator
Posts: 524
Joined: Fri Jan 07, 2011 8:41 pm

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 ?!
YouTube Downloader v3.0
Image
Image
Image
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Whats the error exception?
Top-notch casual Dating
User avatar
Napster1488
VIP - Donator
VIP - Donator
Posts: 524
Joined: Fri Jan 07, 2011 8:41 pm

Agust1337 wrote:
Whats the error exception?
I just made a Database on http://www.db4free.net
Everything works now.
YouTube Downloader v3.0
Image
Image
Image
User avatar
Kobra1984
Member
Member
Posts: 38
Joined: Mon Sep 05, 2011 1:01 pm

cool!
User avatar
rocky4126
VIP - Donator
VIP - Donator
Posts: 258
Joined: Mon Nov 16, 2009 7:39 pm

000webhost doesn't have support for remote MySQL connections, that's why they fail.
Image
10 posts Page 1 of 1
Return to “Tutorials”