Member Avatar for Arturo32

Hi everyone,
Im new to web programming and i need some help, I have something like this:

<td><label>User (Login): </label></td>
    <td><input class="textbox" autofocus="true" type="text" maxLength="7" name="cUser" id="cUser" /></td>
</tr><tr></tr>
<td><label>First Name: </label></td>
    <td><input class="textbox" type="text" maxLength="20" name="cFname" id='cFname' value=""/></td>
</tr><tr></tr><tr>
<td><label>Last Name: </label></td>
    <td><input class="textbox" type="text" maxLength="30" name="cLName" id="cLName" /></td>
</tr><tr></tr>
<td><label>Password: </label></td>
    <td><input class="textbox" type="password" maxLength="15" name="cPass" id="cPass" /></td>
</tr><tr></tr>
.
.
.

I'm actually working in netbeans 7.0.1 using just .jsp and .java and using postgresql 9.1 as my DB. Already defines some .java to get the connection and other class to handle users.
What i'm trying to do here and i have no clue to do so, is to validate if the username is available and dont exist already in my DB. This is a new user register at a website im creating.
What should i do so the moment the user enter his username, and if it is not available show a message as an alert maybe that the user is not available and must choose another.

Please help

Recommended Answers

All 3 Replies

What you have posted is HTML which isn't able to do much for you in terms of checking for user existance but the simplest way to do it (and shall be needed for things like adding the user to the database and logging in) is to use PHP and something like this:

$Username = $_POST['Username'];

mysql_connect ("localhost", "root", "Password");
mysql_select_db ("Database");

$UserCheck = mysql_query("SELECT * FROM Members WHERE Username = '$Username'");
$Count = mysql_num_rows($UserCheck);

if ($Count != 0)
{
    mysql_close();

    die ("User Exists");
}

Obviously this would need to go around with other code to make the registration work, but this basically opens up the database, and checks it against the form. If it comes back with a value other than 0 (ie. there is already a record with that username) then it displays an error message indicating that the username is already taken.

The only down side with this is you need to submit the form to see it, if you do use it MAKE SURE TO SANATIZE ALL INPUT!

Member Avatar for Arturo32

Got it, well i have to learn PHP since it seems to be the common way to do this. Thank you very much AHarrisGsy. By the way its working now so thank you again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.