Hello i'm tryin to load data from server using ajax. Here is my js
<script>
jQuery(document).ready(function($){
$("#mc-prize").click(function(){
event.preventDefault();
$.ajax({
url: "includes/prize.php",
type: "GET",
datatype: "text",
data: {"num": num},
cache: false,
success: function(response){
$("#some-block").append(response);
}
});
});
});
</script>
Here is my prize.php file
<?php
$host = '#';
$user = '#';
$password = '#';
if (isset($_POST['submit'])){
$prize_email = $_POST['email'];
$mysqli = new mysqli($host, $user, $password, $user);
$result = $mysqli->query("SELECT * FROM prize_numbers WHERE email = '" .$prize_email. "'") or die ("Couldn't connect to database.");
$row = $result->fetch_assoc();
if($row['email']) {
echo "Your num: ".$row['num'];
} else {
echo "No email in db";
}
}
?>
But when i'm trying to get some data from db i see an error: "Uncaught ReferenceError: num is not defined"
Whats wrong?
UPD: Sorry what is correct js for my php? What i need to place in data?
Your problem is not in your php but in the js code this code
the variable num is not defined anywhere in the js code
try to use this code: