1,105,363 Community Members

Captcha not working with jquery

Member Avatar
dannybarh
Light Poster
36 posts since Jan 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

am using jquery.min.js to insert a form data into myqsl db.I just added a captcha script i got online,but i keep geting an [ Notice: Undefined index: secretNumber in D:\xampp\htdocs\mim\insert.php on line 25 ].I tryed all i know ,nwwd your help.

javascript code:

<script type="text/javascript">
>         
>         $(document).ready(function(){
>         //Get the input data using the post method when Push into mysql is clicked .. we pull it using the id fields of ID, Name and
> Email respectively...
>         $("#insert").click(function(){
>         //Get values of the input fields and store it into the variables.
>         var hotel=$("#hotel").val();
>         var guestname=$("#guestname").val();
>         var mob=$("#mob").val();
>         var email=$("#email").val();
>         var description=$("#description").val();
>         var calltime=$("#calltime").val();
>         var ftd=$("#ftd").val();          //var ftd=$("#secretNumber").val();
>           
>         //use the $.post() method to call insert.php file.. this is the ajax request
>         $.post('insert.php', {hotel: hotel, guestname: guestname, mob: mob, email: email, description: description, calltime: calltime, ftd:
> ftd,},
>         function(data){
>         $("#message").html(data);
>         $("#message").hide();
>         $("#message").fadeIn(1500); //Fade in the data given by the insert.php file
>         });
>         return false;
>         });
>         });
>         </script>

form field captcha code:

<img src="secureImage.php" alt="CAPTCHA" />
<input name="secretNumber" id="secretNumber"  value="" maxlength="6" />

inser.php:

<?php session_start(); include"inc/config.php";?>

<?
if(!empty($_POST["secretNumber"]) &&
    $_SESSION["secureNumber"]==$_POST["secretNumber"])
{
    //Correct number is entered
    //Pull data from home.php front-end page
 $hotel=$_POST['hotel'];
 $guestname=$_POST['guestname'];
 $mob=$_POST['mob'];
 $email=$_POST['email'];
 $description=$_POST['description'];
 $calltime=$_POST['calltime'];
 $ftd=$_POST['ftd'];
 //Insert Data into mysql
$query=mysql_query("INSERT INTO  cntacts (hotel,guestname,mob,email,description,calltime,ftd) VALUES('$hotel','$guestname','$mob','$email','$description','$calltime','$ftd')");
if($query){
echo "<img src='img/icon/thankyou.gif' border='0' width='400' height='200' align='center'>";
}
else{ echo "An error occurred!".mysql_error(); }
}
{
    //Display error message
     echo "An error occurred!".$_POST["secretNumber"];
}
?>
Member Avatar
diafol
Where are my eyes?
12,980 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 
{hotel: hotel, guestname: guestname, mob: mob, email: email, description: description, calltime: calltime, ftd:
> ftd,},

I can't see secretName in the list. You can't pick up $_POST['var'] directly from a form sent by Ajax. It either has to be sent via parameter (.post or .get or .ajax etc) or serialized and then sent.

So, add the parameter to your list.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: