0

I have this code:

for my view:

<b><input type="text" id="pagibigno" onclick="window.location.assign('#')"/></b>
<div id="pagibig_form">
    <div class="err" id="add_err"></div>
    <form>
        <label>Pagibig Number:</label>
        <input type="text" id="signpagibigno" name="signpagibigno" value="signpagibigno" />
        <input type="text" id="txtpagibigno" name="txtpagibigno" />
        <input type="submit" id="login" value="Login" />
        <input type="button" id="cancel_hide" value="Cancel" />
    </form>
</div>

addField.php

<?php
include 'dbconn.php';    
$signpagibigno = $_GET['signpagibigno'];
$txtpagibigno = $_GET['txtpagibigno'];
echo "INSERT INTO `employer_profile` (`id`, `pagibig_no`, `buss_name`, `sss_no`, `div_code`, `address`, `zip_code`, `tin`, `contact_no`) 
                    VALUES (NULL, '$txtpagibigno', NULL, NULL, NULL, NULL, NULL, NULL, NULL)";
$sql = $conn->prepare("INSERT INTO `employer_profile` (`id`, `pagibig_no`, `buss_name`, `sss_no`, `div_code`, `address`, `zip_code`, `tin`, `contact_no`) 
                    VALUES (NULL, '$txtpagibigno', NULL, NULL, NULL, NULL, NULL, NULL, NULL)");

// mysql_query($sql);    
$sql->execute();
?>

popup.js

$(document).ready(function ()
{
    $("#pagibigno").click(function ()
    {
        $("#shadow").fadeIn("normal");
        $("#pagibig_form").fadeIn("normal");
        $("#user_name").focus();
    });
    $("#cancel_hide").click(function ()
    {
        $("#pagibig_form").fadeOut("normal");
        $("#shadow").fadeOut();
    });
    $("#login").click(function ()
    {
        pagibigno = $("#txtpagibigno").val();
        $.ajax(
        {
            type: "GET",
            url: "addField.php",
            data: data,
            success: function (html)
            {
                if (pagibigno != '')
                {
                    $("#pagibig_form").fadeOut("normal");
                    $("#shadow").fadeOut();
                }
                else
                {
                    $("#add_err").html("Please complete the field");
                }
            },
            beforeSend: function ()
            {
                $("#add_err").html("Loading...")
            }
        });
        return false;
    });
});

when I run the dataField.php the data save to my database. but when I use the view, where the ajax takes place the data did not save. I read this link for this codes Alert in Jquery pagination Please help. thanks

6
  • where is the data variable in this part data: data, Commented Nov 29, 2013 at 4:54
  • i used the GET method so I think the url will provide the data.. am i wrong?? Commented Nov 29, 2013 at 4:57
  • try to remove the data : data, part Commented Nov 29, 2013 at 5:04
  • nothing happen, the problem still there Commented Nov 29, 2013 at 5:07
  • any errors from console? Commented Nov 29, 2013 at 5:07

1 Answer 1

2

You are not passing the data to the php page. See the jquery code below :

$(document).ready(function () {
    $("#pagibigno").click(function () {
        $("#shadow").fadeIn("normal");
        $("#pagibig_form").fadeIn("normal");
        $("#user_name").focus();
    });
    $("#cancel_hide").click(function () {
        $("#pagibig_form").fadeOut("normal");
        $("#shadow").fadeOut();
    });
    $("#login").click(function () {
        txtpagibigno  = $("#txtpagibigno").val();//Getting value from text field
        signpagibigno = $("#signpagibigno").val();//Getting value from text field
        $.ajax({
            type: "GET",
            url: "addField.php",
            data: "txtpagibigno="+txtpagibigno+"&signpagibigno="+signpagibigno,//Passing the values to the php page
            success: function (html) {
                if (pagibigno != '') {
                    $("#pagibig_form").fadeOut("normal");
                    $("#shadow").fadeOut();
                } else {
                    $("#add_err").html("Please complete the field");
                }
            },
            beforeSend: function () {
                $("#add_err").html("Loading...")
            }
        });
        return false;
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.