Data has to be an object.
The property of the object is what you fetch in your $_POST in your PHP script.
$('#add').click(function(){
var num = 0;
$.ajax({
url: 'php/insertlevel.php',
type: 'post',
data: {num: num},
});
});
Your PHP file looks good (assuming $con is the connection). There is only one thing you missed. The single quotes around the value.
<?php
include "connect.php";
$val=$_POST['num'];
echo "i am called dont worry";
$sql="INSERT INTO `level` (`level`) VALUES ('$val')"; //NOTICE, YOU SEE THE SINGLE QUOTES AROUND THE VAL VARIABLE?
$insert=mysqli_query($con,$sql);
if ($insert) {
echo "Data insert";
} else{
echo "not insert";
}
?>
This should do the trick for you.
However, after you have "mastered" this, I highly recommend you to look at PDO or MYSQLI and use the prepared statements. This will ensure you are safe against SQL injections.
I recommend you to look at the PHP manual, but (atleast, for me it was) w3schools explains it in a more of a newbie way. It is however a highly discouraged website when you grow as a developer and actually have to implement for a live environment.
https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php
https://www.w3schools.com/php/php_mysql_prepared_statements.asp