I've searched and searched and can't seem to figure it out from existing posts. I have some specific code and I don't know how to manipulate it to get what I need. //======================== Here is the HTML:
$q_id = get_question_id($holder_id, $pointer);
echo "HERE: ". $q_id; // This line works! I get an id number here.
?>
<html>
<head><title>jQuery + JSON + PHP + AJAX</title></head>
<body>
<div class="container">
<div class="col-md-6">
<form id="myForm" class="form-signin" action="react.php" method="post">
<input type='hidden' name='holder_id' value='<?php echo $_POST['holder_id']; ?>'/>
<input type='hidden' name='pointer' value='<?php echo $_POST['pointer']; ?>'/>
<input type='hidden' name='q_id' value='<?php echo $q_id; ?>'/>
<h3>Question</h3>
<ul></ul>
<button id="sub" class="btn btn-lg btn-primary btn-block" type="submit">Create</button>
</form>
<h3 id="result"></h3>
//========================
Here is the script.js:
function reads() {
$.getJSON("fetch.php", function(data) {
$("ul").empty();
$.each(data.result, function(){
var output = $("").val();
output = "<li><h4>"+ this['id'] +": " + this['question'] +"</h4></li>";
output += "<div class=\"checkbox\">";
output += "<label><input name=\"a\" type=\"checkbox\">"+ this['a'] +"</label><br/>";
output += "<label><input name=\"b\" type=\"checkbox\">"+ this['b'] +"</label><br/>";
output += "<label><input name=\"c\" type=\"checkbox\">"+ this['c'] +"</label><br/>";
output += "<label><input name=\"d\" type=\"checkbox\">"+ this['d'] +"</label><br/>";
output += "</div>";
$("ul").append(output);
});
});
}
//========================
Here is the fetch.php:
<?php
include_once('db.php');
$q_id = $_POST['id'];
$sql = "SELECT * FROM questions WHERE id = {$q_id} LIMIT 1";
$res = mysqli_query($connection, $sql);
$result = array();
while( $row = mysqli_fetch_array($res) )
array_push($result, array( 'id' => $row['id'],
'question' => $row['question'],
'a' => $row['a'],
'b' => $row['b'],
'c' => $row['c'],
'd' => $row['d']
));
echo json_encode(array("result" => $result));
?>
I'm new to learning this sort of thing and I'm having problems extracting the $_POST['id'] just before the sql statement in the "fetch.php" file. Normally, I can put print_r($_POST) near the top of any php page and see all the vars listed. Under these circumstances, I'm not seeing any vars arrive at the php file. If I put print_r($_POST) on the html, I get values from the previous page, but the fetch.php file doesn't seem to be getting any POST vars.
I imagine the answer to my quandary is probably something very elementary, but I need help and reading through all these posts that are very similar but not quite similar enough to my problem isn't getting me very far. I've actually gotten this far, not knowing much, just by reading posts...so I am trying and I hope there's not a post out there that I just didn't see or learn from before posting this.
Thanks!