I have phppage.php which connects to a MySQL database:
<?php
$list = 'A,B,C';
$cxn = mysqli_connect("localhost", $username, $password, $database) or die("Didn't connect");
$query = "SELECT * FROM Questions3 WHERE 1 IN ($list) ORDER BY RAND() LIMIT 10";
$result = mysqli_query($cxn,$query) or die ("Didn't work");
while( $row = mysqli_fetch_assoc($result) )
{
echo "<div>";
echo $row['columnname'];
echo "</div>";
}
This pulls out 10 random database entries where columns A, B or C have the value "1".
This page runs fine on its own. But I actually need to call this using AJAX (which I'm new to), from another page using checkboxes. So instead of
$list = 'A,B,C'
I need
$list = "data1"
where the jQuery on my main page is:
$(document).ready(function(){
$("button").click(function(e){
e.preventDefault();
var data1 = 'A,B,C';
$.ajax({url:"phppage.php", type:"POST", data:data1, success:function(result){
$("#display").html(result);
}});
});
})
And the html is:
<button>Press</button>
<div id="display">Data should show here</div>
(Obviously in this simplified version I'm ignoring the checkboxes).
However, when I press the button, I get "Didn't work" displayed. So "data1" in my JQuery is not transferring to become my $list in the PHP.
What's wrong with my AJAX: how can I transfer the "data1" string?
die ("Didn't work");withdie( mysqli_error($cxn) );What output do you see now? (An MySQL error, don't you?)$_POST["data"]).. is that deliberate?