Jump to content


Check out our Community Blogs

PF2G

Member Since 01 Dec 2011
Offline Last Active Dec 25 2011 07:07 AM
-----

Topics I've Started

Registration - Check for empty textboxs

25 December 2011 - 07:06 AM

I'm doing a registration system and as you can see when i verify the fields, if it's empty it says that the FIELD_1 misses. And what i want is if the field is empty says that and then goes back, but i don't wanto the info already written disappears.

I'm using ajax, i never worked with it, so i'm gonna ask you if i'm doing everything ok:


registration form:

    <!---------VALIDAÇÃO AJAX---------->
    <link rel="stylesheet" type="text/css" href="style_val.css" />
    <script src="ajaxforms.js" type="text/javascript" language="javascript"></script>
    <!--------------------------------->
    <div class="indent">
     
    <h2> Inscrição </h2>
     
    <form action="" method="post">
    <fieldset>
    <legend> ALUNO </legend>
     
    <br/>
    <div class="title" class="field"><label>Username*: </label><input type="text" size="30" name = "username" OnChange="CheckField(this)" tabindex="1"/></div>
    <div id="username" class="message"></div>


ajaxform:

    var AJAXForms = false;
    var LastField = null;
    var isIE = false;
    // on !IE we only have to initialize it once
    if (window.XMLHttpRequest) {
    AJAXForms = new XMLHttpRequest();
    }
     
    function CheckField(field) {
     
    if (window.XMLHttpRequest) {
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
    AJAXForms = new ActiveXObject("Microsoft.XMLHTTP");
    }
     
    AJAXForms.onreadystatechange = processChange;
    AJAXForms.open("GET", "check.php?op=ajax&field=" +field.name+"&value=" + field.value);
    LastField = field.name;
    AJAXForms.send(null);
    }
     
    function processChange() {
    if (AJAXForms.readyState == 4) {
     
    var res = document.getElementById(LastField);
    res.innerHTML = AJAXForms.responseText;
    res.style.visibility = "visible";
     
    }
    }


style:


    body,* {
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    font-size: 12px;
    }
     
    .ajform {
    background: #FF7F50;
    border:1px solid black;
    padding: 4px;
    margin: 4px;
    width: 500px;
    }
     
    .title {
    width: 60%;
    background: #FFAF91;
    padding: 4px;
    }
     
    .field {
    padding: 4px;
    background: #FFE691;
    }
     
    .message {
    background: white;
    border:1px solid #FF7F50;
    visibility: hidden;
    margin: 4px;
    text-align: center;
    }
     
    .green {
    color: Green;
    }
     
    .red {
    color: red;
    }
     
    .category {
    background: #E0FF91;
    padding: 4px;
    }

I didn't do anything yet, i was just checking the page if there was any error and it's like this:
Attached File  13243604.jpg   111.99KB   60 downloads

The headers are in a seperated page 'top.php'.

Please help me.

Thank you,
PF2G

Register admin (Connect MySQL DB)

01 December 2011 - 10:27 AM

Hi i'm having problems in register admin. Before it didn't insert, but now i have other problem, it doesn't open the registering form.

Here is the login.form:
Imports MySql.Data.MySqlClient

Public Class Login
    Dim server As String = "Server=localhost;Database=escola_musica;Uid=root;Pwd=;"
    'Dim server As String = "Server=localhost;Database=esola_musica;Uid=root;Pwd=;"
    Dim con As New MySqlConnection
    Dim da As New MySqlDataAdapter
    Dim sql As String
    Dim cmd As New MySqlCommand(sql, con)
    Dim dr As MySqlDataReader

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Ligação �* BD
        con.ConnectionString = server

        Try
            If con.State = ConnectionState.Closed Then
                con.Open()
            Else
                con.Close()
                MsgBox("Ligação falhada!!")
            End If
        Catch erro As Exception
            MsgBox(erro.ToString)
        End Try

        'Log in
        sql = "SELECT * FROM admin WHERE username = '" & user_box.Text & "' AND pass = '" & pass_box.Text & "'"

        With cmd
            .CommandText = sql
            .CommandType = CommandType.Text
            .Connection = con

        End With
        dr = cmd.ExecuteReader

        If dr.Read Then
            If (dr("username") <> user_box.Text) Or (dr("pass") <> pass_box.Text) Then
                MsgBox("Utilizador ou pass invalida")
                Exit Sub
            Else
                MsgBox("correcto!")
                Principal.Show()
                con.Close()
                Me.Close()
                Exit Sub
            End If
        End If


        If Trim(user_box.Text) <> "" And Trim(pass_box.Text) <> "" Then
            Principal.Show()
            Me.Close()
        Else
            MsgBox("erro! -.-' ")
        End If
    End Sub

    Private Sub reg_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reg_button.Click
        Admin_Reg.Show()
        Me.Close()
    End Sub
End Class


Here is the admin_reg.form:
Imports MySql.Data.MySqlClient
Public Class Admin_Reg
    Dim server As String = "Server=localhost;Database=escola_musica;Uid=root;Pwd=;"
    'Dim server As String = "Server=localhost;Database=esola_musica;Uid=root;Pwd=;"
    Dim con As New MySqlConnection
    Dim sql_sel As String = "SELECT (username, pass) FROM admin WHERE username = '" & user_box.Text & "' AND pass = '" & pass_box.Text & "'"
    Dim dr As MySqlDataReader
    Dim da As New MySqlDataAdapter
    Dim cmd As New MySqlCommand
    Dim sql_ins As String = "INSERT INTO admin (username, pass)VALUES ('" & user_box.Text & "','" & pass_box.Text & "')"

    Private Sub reg_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reg_button.Click

        'Ligação �* BD
        con.ConnectionString = server

        Try
            If con.State = ConnectionState.Closed Then
                con.Open()
            Else
                con.Close()
                MsgBox("Ligação falhada!!")
            End If
        Catch erro As Exception
            MsgBox(erro.ToString)
        End Try

        cmd.Connection = con
        cmd.CommandText = sql_ins

        'start query
        da.SelectCommand = cmd

        dr = cmd.ExecuteReader()
        'see if user exits.
        If dr.HasRows = 0 Then
            MsgBox("Invalid Authkey")
        Else
            MsgBox("Authentication Key accepted!")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Login.Show()
        Me.Close()
    End Sub
End Class


Can someone help me?

Thank you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download