An7hony Posted July 25, 2014 Share Posted July 25, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/290108-missing-php-variable/ Share on other sites More sharing options...
gristoi Posted July 25, 2014 Share Posted July 25, 2014 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'); } }); Quote Link to comment https://forums.phpfreaks.com/topic/290108-missing-php-variable/#findComment-1486124 Share on other sites More sharing options...
An7hony Posted July 25, 2014 Author Share Posted July 25, 2014 thanks i'll give it a try Quote Link to comment https://forums.phpfreaks.com/topic/290108-missing-php-variable/#findComment-1486130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.