Hi,
I'm working on a registration form and one of the checks I need to perform as the form is used is on the username. I need to ensure that it is not already in use. I am getting a little stuck. Here's the code involved (sorry there's quite a bit) and then I'll explain the problem.
HTML (relevant sample) -
<div class="row">
-
<span class="label" id="usernamelabel">
-
<span class="warninglabel">Username:</span>
-
</span>
-
<span class="formw">
-
<input id="username" type="text" size="47" onchange="validateItem('usernamelabel',this.value,'Username:',4,false,5,true);" title="Username, for use on the Forum" />
-
(6-18 alpha numeric characters)
-
</span>
-
</div>
-
Javascript (3 functions involved) -
function stateChanged()
-
{
-
if (goXMLHTTP.readyState==4 || goXMLHTTP.readyState=="complete")
-
{
-
document.getElementById(gcItemID).innerHTML=goXMLHTTP.responseText;
-
}
-
}
-
-
function GetXmlHttpObject()
-
{
-
if (window.XMLHttpRequest)
-
{
-
goXMLHTTP=new XMLHttpRequest()
-
}
-
else if (window.ActiveXObject)
-
{
-
goXMLHTTP=new ActiveXObject("Microsoft.XMLHTTP")
-
}
-
if (goXMLHTTP==null)
-
{
-
alert ("Browser does not support HTTP Request")
-
return
-
}
-
}
-
-
-
function validateItem(pcID,pcItem,pcDisplay,pnType,plPopulateExtra,pnNumberOfItems,plCheckDatabase)
-
{
-
var lcRegExp, llIsValid, llUseRegExp
-
llIsValid = false
-
llUseRegExp = false
-
switch (pnType)
-
{
-
case 1: // UK postcode
-
pcItem = pcItem.toUpperCase()
-
lcRegExp = '^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA$'
-
llUseRegExp = true
-
break;
-
case 2: // email address
-
lcRegExp = '^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$'
-
llUseRegExp = true
-
break;
-
case 3: // number of set length - basic telephone number check
-
lcRegExp = '^[0-9]{6,11}$'
-
llUseRegExp = true
-
break;
-
case 4: // username and password validation - alpha numeric characters 6-18 characters long
-
lcRegExp = '^[A-Za-z0-9]{6,18}$'
-
llUseRegExp = true
-
break;
-
}
-
-
if (llUseRegExp)
-
{
-
if (pcItem.match(lcRegExp))
-
{
-
if(plCheckDatabase)
-
{
-
GetXmlHttpObject() // sets the global variable
-
gcItemID = pcID
-
gcUrl = "../lib/datacheck.php?check=1&tocheck='" + pcItem + "'"
-
goXMLHTTP.onreadystatechange=stateChanged
-
goXMLHTTP.open("GET",gcUrl,true)
-
goXMLHTTP.send(null)
-
-
}
-
else
-
{
-
llIsValid = true
-
}
-
}
-
else
-
{
-
llIsValid = false
-
}
-
}
-
else
-
{
-
if (pcItem == null||pcItem == ""||pcItem.length < 2)
-
{
-
llIsValid = false
-
}
-
else
-
{
-
llIsValid = true
-
}
-
}
-
-
if (!plCheckDatabase)
-
{
-
if (llIsValid)
-
{
-
document.getElementById(pcID).innerHTML = pcDisplay
-
if (gnValidationCount >= 1)
-
{
-
gnValidationCount = gnValidationCount - 1
-
}
-
}
-
else
-
{
-
document.getElementById(pcID).innerHTML = "<span class='warninglabel'>" + pcDisplay + "</span>"
-
if (gnValidationCount <= pnNumberOfItems)
-
{
-
gnValidationCount = gnValidationCount + 1
-
}
-
}
-
}
-
-
if (gnValidationCount == 0)
-
{
-
hideOrShowInput("complete",false)
-
}
-
else
-
{
-
hideOrShowInput("complete",true)
-
}
-
if (plPopulateExtra)
-
{
-
populateExtra(lcSource, lcDestination, true, true)
-
}
-
}
-
PHP (the page referenced in validateItem()) -
<?php
-
-
// establish what is being checked via the $_REQUEST variable
-
$lnCheckType = $_REQUEST['check'];
-
$lcItemToCheck = $_REQUEST['tocheck'];
-
switch($lnCheckType)
-
{
-
case 1: // check for presence of username, will only ever be one match
-
$lcCheckSQL =
-
"SELECT 1 as test
-
FROM credential
-
WHERE username like '$lcItemToCheck'" ;
-
-
$laResult = $loDB->queryGetData($lcCheckSQL);
-
-
foreach($laResult as $lcTest)
-
{
-
$llAvailable = $lcTest['test'];
-
if($llAvailable > 0)
-
{
-
echo "<span class='warninglabel'>Username in use:</span>";
-
}
-
else
-
{
-
echo "Username:";
-
}
-
}
-
break;
-
-
case 2:// just to show that we can expand this system should we ever need to
-
echo "case = 2";
-
break;
-
}
-
?>
-
The Problem
The php will echo the tow variables from $_REQUEST, and the $lcCheckSQL is defined correctly. However, there appears to be a problem with the way the SQL is executing as all that happens is the label that is supposed to change is blanked.
I believe the connection to the database is available, this is set at the top of the page that has the form on it and so should be available. Even if I add a connection to this page the behaviour is the same.
This is really frustrating now and I'd love some help with this.
Thanks for reading (I know it was long)
nathj
4 2003
try this query
"SELECT COUNT(*) as test FROM credential WHERE username='$IcItemToCheck'";
(note that i put single quotationmarks around the variable
another to check would be to just select everything WHERE username='yourvar' and test if the $result has any rows in it. If it has, the username or whatever is ofcourse illegal :)
try this query
"SELECT COUNT(*) as test FROM credential WHERE username='$IcItemToCheck'";
(note that i put single quotationmarks around the variable
another to check would be to just select everything WHERE username='yourvar' and test if the $result has any rows in it. If it has, the username or whatever is ofcourse illegal :)
Thanks for the help, I have further tracked down the trouble with this. If i change the php file to: -
-->
-
<?php
-
// establish what is being checked via the $_REQUEST variable
-
$lnCheckType = $_REQUEST['check'];
-
$lcItemToCheck = $_REQUEST['tocheck'];
-
-
//establish connection - using dataobject.php did not work?
-
$lvCon = mysql_connect('server', 'user', 'password');
-
if (!$lvCon)
-
{
-
die('Could not connect: ' . mysql_error());
-
}
-
mysql_select_db("clfdb", $lvCon);
-
-
// branch the code
-
switch($lnCheckType)
-
{
-
case 1: // check for presence of username, will only ever be one match or no match
-
$lcToDisplay = "Username:";
-
-
$lcCheckSQL =
-
"SELECT 1 as test
-
FROM credential
-
WHERE username like $lcItemToCheck" ;
-
-
$result = mysql_query($lcCheckSQL);
-
-
while ($row = mysql_fetch_array($result))
-
{
-
$lnAvailable = $row['test'];
-
if ($lnAvailable = 1)
-
{
-
$lcToDisplay = "<span class='warninglabel'>Username in use:</span>";
-
}
-
}
-
-
echo $lcToDisplay;
-
break;
-
-
case 2:// just to show that we can expand this system should we ever need to
-
echo "case = 2";
-
break;
-
}
-
?>
-
it works just fine. This indicates that there is some problem in the way I was attempting to use the data abstraction layer I have developed.
I have changed the SQL to your suggested use of COUNT(*) as this makes more sense when reading. Otherwise I will leave it as it is shown above for the time being and try to figure out a way of not duplicating code later on.
Thanks for the help.
nathj
Heya, nathj.
Thanks for using CODE tags! Did you know that you can specify a language for your CODE tags to make your source code easier to read?
You will still need to use [/code] to close your code blocks, regardless of the language, but you can the use one of these tags to open your code block:
[code=html]
[code=javascript]
[code=php]
and so on.
Thanks!
MODERATOR
Heya, nathj.
Thanks for using CODE tags! Did you know that you can specify a language for your CODE tags to make your source code easier to read?
You will still need to use [/code] to close your code blocks, regardless of the language, but you can the use one of these tags to open your code block:
[code=html]
[code=javascript]
[code=php]
and so on.
Thanks!
MODERATOR
I did not know all that, I will make use of this in future - thanks for the pointer.
I should also say thanks for the help, I have now got this working. The relevant controls validated based on a regular expression and on the database as I wanted them to and the form works a treat.
Many thanks
Nathan
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joeri KUMBRUCK |
last post by:
Hello,
I'm trying to create an ASP page where users can type in a username
and password, and these credential should be checked with active
directory. If username and password are correct, the...
|
by: arktikturtle |
last post by:
Hi! I'm looking for a way to validate a password within PL/SQL. I want to
write
CREATE PROCEDURE change_password(old_password IN VARCHAR2)
IS
BEGIN
-- check if old_password is correct... but...
|
by: Paul Steele |
last post by:
I'm writing a C# program that needs to validate an Active Directory
username/password? The program will be running on a workstation that is not
part of the domain. It doesn't have to do anything...
|
by: Steffen Balslev |
last post by:
I tried to find a way to validate user credentials using C#, searching google and lots of other news and kb sites left me without a solution.
You can use a SSPI but it's that easy to implement so...
|
by: Joeri KUMBRUCK |
last post by:
Hello,
I'm trying to create an ASP page where users can type in a username
and password, and these credential should be checked with active
directory. If username and password are correct, the...
|
by: Raghuram |
last post by:
if i want to validate the LDAP user
like i will provide him with the domain name but not the user name and pass
when the user enters the user name and pass i should validate towards my
domain, and...
|
by: ojnoka |
last post by:
Hi,
I am a newbie. I don't know javascript. I use the free javascripts and try to understand them.
I have a javascript now, to validate username and password. I paste it below. My question now. Is...
|
by: sc0705837 |
last post by:
Hi there I am trying to get my action page of the website I'm building to check to see if the form input values are empty, if they are not it will then check to see if any of the form inputs contain...
|
by: ghjk |
last post by:
I have a web site with several web pages. They are having different number of variables. eg: first page having 4 variables in the form(Name, Phone, ID, Gender)
second page having 10 variables in the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |