gpt4 book ai didi

javascript - 基于php变量的mysql查询

转载 作者:行者123 更新时间:2023-11-29 10:48:16 25 4
gpt4 key购买 nike

这是我的代码

  $query = "select ((recipients.maennlichDeutsch+recipients.maennlichAuslaender+recipients.weiblichDeutsch+recipients.weiblichAuslaender)/inhab.Einwohner) as Sozialhilfeempfaenger,jahr from recipients left join education on recipients.Bundesland = education.FK_Land and recipients.Jahr = education.FK_Jahr left join inhab on recipients.Bundesland = inhab.FK_land and recipients.Jahr = inhab.FK_Jahr where education.Abschluss in ('Hauptschulabschluss') and recipients.Bundesland = '.$_REQUEST['land'].'";
$result=mysqli_query($db, $query) or die('Error querying database.');

$q = "select ((education.weiblich+education.maennlich)/inhab.Einwohner) as 'niedriger Bildungsstand',Jahr from recipients left join education on recipients.Bundesland = education.FK_Land and recipients.Jahr = education.FK_Jahr left join inhab on recipients.Bundesland = inhab.FK_land and recipients.Jahr = inhab.FK_Jahr WHERE education.Abschluss in ('Ohne Haupschulabschluss','Hauptschulabschluss') and recipients.Bundesland = '.$_REQUEST['land'].'";
$r=mysqli_query($db, $q) or die('Error querying database.');

$_REQUEST['land']。我正在尝试获取下拉菜单的选定值。变量 land 正在工作,我可以毫无问题地回显它。即使没有 $_REQUEST['land'],查询也能正常工作。

但现在我收到 500 错误。你知道我在这里做错了什么吗?

最佳答案

您应该转义变量以与双引号连接(因为您以双引号开始字符串),请更改此:

$q = "... and recipients.Bundesland = '.$_REQUEST['land'].'";

对此:

$q = "... and recipients.Bundesland = '".$_REQUEST['land']."'";

与第一个查询相同。希望对您有所帮助。

关于javascript - 基于php变量的mysql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44184989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com