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
https://forums.phpfreaks.com/topic/290108-missing-php-variable/
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');
 	}
 });

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.