0
你好,我有一個驗證碼使用Ajax的工作,但它沒有將我的表格的相關信息進入數據庫,它插入空行,我沒有任何線索,爲什麼 這裏是我的代碼:阿賈克斯驗證碼後,將其插入數據庫
require_once('inc/recaptchalib.php');
$publickey = "6LdW1N0SAAAAADMIPPkOGd939meXV9a9qDwwcxbu"; // you got this from the signup page
$privatekey = "";
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var RecaptchaOptions = {
theme : 'clean'
};
</script>
<script type="text/javascript">
function validateCaptcha()
{
challengeField = $("input#recaptcha_challenge_field").val();
responseField = $("input#recaptcha_response_field").val();
//alert(challengeField);
//alert(responseField);
//return false;
var html = $.ajax({
type: "POST",
url: "ajax.recaptcha.php",
data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
async: false
}).responseText;
if(html == "success")
{
$("#captchaStatus").html("Success. Submitting form.");
return false;
// Uncomment the following line in your application
//return true;
}
else
{
$("#captchaStatus").html("Your captcha is incorrect. Please try again");
Recaptcha.reload();
return false;
}
}
</script>
這裏是我想要插入到數據庫中的表單:
<form id="loginform" name="loginform" action="" method="post" enctype="multipart/form-data" onSubmit="return validateCaptcha()" >
<fieldset class="step">
<p>
<label for="nick">Nickname:</label>
<input type="text" name="nick" value="" id="nicknamee" value="" >
</p>
<p>
<label for="email">Email:</label>
<input type="text" name="email" value="" id="email_comm" value="" >
</p>
<p>
<textarea class="text-input textarea wysiwyg" name="add_comment" id="text_commentt"></textarea>
</p>';?>
<div id="login">
<?php echo recaptcha_get_html($publickey);?>
<p style="color: red;" id="captchaStatus"> </p>
</div>
<?php
echo'
<p style="margin-top:200px;"><button id="vote_petiton_submit" type="submit" ></button>
</p>
</fieldset>
</form>
的ReCaptcha現在的核查和數據庫插入文件。驗證是可以的,只需要在數據庫中插入數據不正確,它不會發布值。
<?php
require_once('inc/recaptchalib.php');
require_once('engine/db.php');
$publickey = "6LdW1N0SAAAAADMIPPkOGd939meXV9a9qDwwcxbu"; // you got this from the signup page
$privatekey = "";
mysql_query("SET NAMES utf8");
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
?>success<?
$nick=$_REQUEST['nick'];
$type=0;
$email=$_REQUEST['email'];
$descr=$_REQUEST['add_comment'];
$descriere=strip_tags($descr,'<br><p><a><i><u><b>');
$id=150;
$insert = "INSERT INTO comments (`nickname`,`desc`,`email`,`type`,`id_pet_dem_des`)
VALUES ('$nick','$descriere','$email','$type',$id)";
$result = mysql_query($insert)
or die("query failed: " . mysql_error());
$queryz = "update petition set comments=comments+1 where id_petition='$id'";
$resultz = mysql_query($queryz)
or die("query failed: " . mysql_error());
}
else
{
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
?>
Thnx提前。
我已刪除了您的私鑰(需要同行評審),從阿賈克斯後量變到質變的數據修復它,但它仍然在編輯歷史可見。如果您刪除問題並重新發布而沒有私鑰,這可能是最好的選擇。 – 2013-03-05 18:54:03
沒有人可以照亮我?:) – 2013-03-05 21:40:17
這可能是最好的你重新生成你的私鑰 – Mchl 2013-03-05 22:03:57