I can validate the captcha successfully, but when I set the button property 'Action' to 'Submit form, the captcha does not work, nor does the validation on username and password. When I set it back to 'None", Captcha works, Data not validated. The code below is quite long, but it will give an idea of what I am trying here.
<?PHP
$uname = "";
$pword = "";
$errorMessage = "";
//==========================================
// ESCAPE DANGEROUS SQL CHARACTERS
//==========================================
function quote_smart($value, $handle) {
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value, $handle) . "'";
}
return $value;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$uname = $_POST['UserName'];
$pword = $_POST['MemberPw'];
$uname = htmlspecialchars($uname);
$pword = htmlspecialchars($pword);
//==========================================
// CONNECT TO THE LOCAL DATABASE
//==========================================
$user_name = "auctiontestuser"; //Limited access
$pass_word = "********";
$database = "login";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$uname = quote_smart($uname, $db_handle);
$pword = quote_smart($pword, $db_handle);
$SQL = "SELECT * FROM login WHERE L1 = $uname AND L2 = md5($pword)";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
//====================================================
// CHECK TO SEE IF THE $result VARIABLE IS TRUE
//====================================================
if ($result) {
if ($num_rows > 0) {
session_start();
$_SESSION['login'] = "1";
header ("Location: index.html");
}
else {
session_start();
$_SESSION['login'] = "";
header ("Location: Register.php");
}
}
else {
$errorMessage = "Error logging on";
}
mysql_close($db_handle);
}
else {
$errorMessage = "Error logging on";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Copyright 2006 WebCheatsheet.com
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link href="styles/LogMeIn.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#LoginData #form1 label {
font-family: Verdana, Geneva, sans-serif;
}
</style>
</head>
<body>
<div id="container">
<div id="Logo"><a href="index.html"><img src="Images/Logo/Logo.png" alt="Login or register." width="968" height="110" title="Click to go back to the Home Page." /></a></div>
<div id="LoginData">
<div id="EmptySpacer">Please enter your Login Information below.</div>
<script type="text/javascript">
function setFocus(){
document.getElementById("UserName").focus();
}
</script>
<script language="JavaScript" type="text/javascript" src="ajax_captcha.js"></script>
<body onload="setFocus()">
<form id="frmCaptcha" name="frmCaptcha">
<p>
<label for="UserName">Username:</label>
<strong>
<input name="UserName" type="text" id="UserName" title="Enter your Username or E-Mail Address." size="50" maxlength="100" />
</strong></p>
<p>
<label for="MemberPW">Password :<br />
</label>
<input name="MemberPW" type="password" id="MemberPW" title="Enter Password" size="50" maxlength="16" />
</p>
<table width="470">
<tr>
<td width="173" align="left">
<label for="captcha">Security Code:</label>
</td>
<td width="238" align="justify">
<input name="txtCaptcha" type="text" id="txtCaptcha" title="Enter Security Code" size="32" maxlength="10" />
</td>
<td width="43">
<img src="create_image.php" name="imgCaptcha" id="imgCaptcha" />
</td>
</tr>
<tr>
<td> </td>
<td>
<input id="btnCaptcha" type="button" value=" Login " name="btnCaptcha"
onclick="getParam(document.frmCaptcha)" />
</td>
<td> </td>
</tr>
</table>
<div id="result"> </div>
</form>
</div>
</div>
<?PHP print $errorMessage;?>
</body>
</html>
Any ideas?