我决定在我的程序中添加一个删除功能,但由于某种原因,DELETE FROM 不起作用。我提供了一些有用的代码,它们会有所帮助:
JavaScript:
function removeAgeGender(id) {
console.log("Entering removeAgeGender");
if (id == 'national age gender') {
var data = $('[name="remove_age_gender[]"]').serialize();
console.log(data);
$.ajaxSetup({async:false});
$.post('/CensusDatabase/database_scripts/NationalAgeGender.php', {remove_age_gender : data });
nationalAgeGender();
}
if (id == 'arizona age gender') {
var data = $('[name="remove_age_gender[]"]').serialize();
$.ajaxSetup({async:false});
$.post('/CensusDatabase/database_scripts/ArizonaAgeGender.php', {remove_age_gender : data });
arizonaAgeGender();
}
}
PHP:
if(isset($_POST['remove_age_gender'])) {
$boxData = $_POST['remove_age_gender'];
$removeValue = array();
parse_str($boxData, $removeValue);
removeRow($removeValue, $link);
}
function removeRow($removeValue, $link) {
$removeValue = $removeValue['remove_age_gender'];
$value = $removeValue[0];
$query = "DELETE FROM national_age_gender_demographics WHERE age_group='$value'";
$escapedQuery = mysqli_real_escape_string($query);
$result = mysqli_query($link,$escapedQuery);
if(!$result) die( "Query: " . $escapedQuery . "\nError:" . mysql_error() );
}
有谁知道我做错了什么?