rahulpatel
Programmer
On my form I have a textbox and a button. The textbox searches my database and returns a true or false value.(Yes it is in the database or No it's not) This works well. The button is a button and not submit. There is an 'onclick' value which uses another page to do the searching and returns the value via ajax. However, I want to add a bit of security with captcha but every demo and tutorial I've found uses the button as submit.
This is the page that retrieves the data..
If it looks familiar, yes I'm learning from a book. This works fine but I have no idea where to add my captcha box and how to make it work from the button I already have on the form as most tutorials have submit buttons.
Any ideas where to head would be gratefully accepted.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>.: Registrations :.</title>
<script type="text/javascript">
var url = "GetCustomerData.php?id="; // The server-side script
function handleHttpResponse() {
if (http.readyState == 4) {
if(http.status==200) {
var results=http.responseText;
document.getElementById('divCustomerInfo').innerHTML = results;
}
}
}
function requestCustomerInfo() {
var sId = document.getElementById("txtCustomerId").value;
http.open("GET", url + escape(sId), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (!xmlhttp){
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
}
return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
</script>
<link href="rego.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="search">
<form>
<p>
<input type="text" id="txtCustomerId" value="" />
<input type="button" value="Search" onClick="requestCustomerInfo()" />
</p>
<div id="divCustomerInfo"></div>
</form></div>
<div id="title"> </div>
</body>
</html>
This is the page that retrieves the data..
Code:
<?php
//customer ID
$sID = $_GET["id"];
//variable to hold customer info
$sInfo = "";
$sInfo1 = "<a href=login.php>Log in</a> or <a href=register.php>register</a> for more information";
$sDBServer = "localhost";
$sDBName = "XXXX";
$sDBUsername = "######";
$sDBPassword = "######";
$sQuery = "select * from number where number = ".$sID;
$oLink = mysql_connect($sDBServer,$sDBUsername,$sDBPassword);
@mysql_select_db($sDBName) or $sInfo="Unable to open database";
//create the SQL query string
if ($sID == "")
{
echo "<h4>Please enter a value.</h4>";
exit;
}
if($sInfo == '') {
if($oResult = mysql_query($sQuery) and mysql_num_rows($oResult) > 0) {
$aValues = mysql_fetch_array($oResult,MYSQL_ASSOC);
$sInfo = "Number is registered<br />"."$sInfo1";
} else {
$sInfo = "Number is not registered.";
}
}
mysql_close($oLink);
?>
</head>
<body>
<div id="divInfoToReturn"> <?php echo $sInfo ?> </div>
</body>
</html>
If it looks familiar, yes I'm learning from a book. This works fine but I have no idea where to add my captcha box and how to make it work from the button I already have on the form as most tutorials have submit buttons.
Any ideas where to head would be gratefully accepted.