Jump to content

missing php variable


An7hony

Recommended Posts

The user will click on the first button (.Applybutton) which opens a bootstrap modal with the ID ApplyModal. From then on an apply button (.SendButton) will send the job id that is passed in the first button press $_POST['jobid'] to the database.
 
The problem:
 
The JSON is displaying correctly in the console however the $_POST['jobid'] data is being ignored in the second button press on the modal when inserting into the database. $_POST['send'] is just being used to recognise the button press.
 
 
//Open modal button pressed
$(".Applybutton").click(function() {

var element = $(this);
var ID = $(this).attr("id");
var dataString = 'jobid='+ ID;

$.ajax({
type: "POST",
dataType: "json",
    url: "actions/ApplyData.php",
    data: dataString,
    cache: false,
            success: function(data)
            {
console.log(JSON.stringify(data));
$('#ApplyModal').modal('show');
 	}
 });

return false;
});

        //Send application button pressed on modal
$(".SendButton").click(function() {

var dataString = 'send=101';

$.ajax({
type: "POST",
dataType: "json",
    url: "actions/ApplyData.php",
    data: dataString,
    cache: false,
            success: function(data)
            {
            	console.log(JSON.stringify(data));
 	}
 });

return false;

});
 

ApplyData.php

<?php  
session_start();
header('Content-type: application/json');
include '../includes/connection.php';

$candidateEmail = mysqli_real_escape_string($con, $_SESSION['email']);
$covering_letter = mysqli_real_escape_string($con, $_POST['coveringletter']);

$response_object = array('status' => 'success');

if (isset($_POST['jobid'])) {

        $message = $_POST['jobid'];

    }

if (isset($_POST['send'])) {

        $message = "Successfully Applied.";

        $querySend = mysqli_query($con, "INSERT INTO applied_jobs (candidate_email, job_id) VALUES ('$candidateEmail','".$_POST['jobid']."')");

}

 	$response_object['message'] = $message; 
  	print json_encode($response_object);

?>


Any ideas?

 

Link to comment
Share on other sites

you're not posting jobId anywhere in that code. if you want job id to be posted then you need to specify it:

$.ajax({
type: "POST",
dataType: "json",
    url: "actions/ApplyData.php",
    data: {
           jobid:  ID
           },
    cache: false,
            success: function(data)
            {
console.log(JSON.stringify(data));
$('#ApplyModal').modal('show');
 	}
 });
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.