我正在使用 jquery 和 ajax 调用 php 页面 res.php。代码是: -
$('#submit_button').click(function () {
buildingVal = $("#building");
levelVal = $("#level");
data = 'building=' + buildingVal.val() + 'level=' + levelVal.val();
$.ajax( {
url: "res.php",
type: "POST",
data: data,
success: function (data) {
$('#npc').html(data);
}
});
});
res.php 页面代码是:-
<?php
//connect to the database
$con = mysql_connect("localhost","root","12345") or die("error ".mysql_error());
//connect to the travian table
mysql_select_db("trav",$con) or die("error ".mysql_error());
$building = mysql_real_escape_string($_GET['building']);
$level = mysql_real_escape_string($_GET['level']);
$query = "select * from ";
$query = $query . $building;
$query = $query . "where lvl=" . $level;
$query = $query . ";";
$result = mysql_query($query) or die('Error in Child Table!');
$data = mysql_fetch_assoc($result);
echo '<table><tr><td>Lumber=$data["lumber"]</td><td>Clay=$data["clay"]</td><td>Iron=$data["iron"]</td><td>Crop=$data["crop"]</td>';
?>
我收到错误
Notice: Undefined index: building in C:\xampp\htdocs\debal\res.php on line 8
Notice: Undefined index: level in C:\xampp\htdocs\debal\res.php on line 9
Error in Child Table!
我如何提取发送到页面的两个参数并在 sql 查询中使用它们从数据库中的表中检索数据。请问你能帮我吗..