gpt4 book ai didi

php - mysql 匹配...通过引用字符串变量

转载 作者:行者123 更新时间:2023-11-29 13:02:53 25 4
gpt4 key购买 nike

我试图使用 PHP 表单中两个不同表单字段的输入在两个不同列中查找匹配项。我正在引用在我的 mysql 代码中输入到表单中的两个字符串变量,但它返回一个错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MATCH (abcdef) AGAINST name' at line 1

我尝试了一些语法变体,但没有成功。

$name = mysql_real_escape_string($_POST['studentname']);
$num = mysql_real_escape_string($_POST['studentnum']);
$qw = "SELECT name FROM students MATCH ($name) AGAINST name";
$qw1 = "SELECT studentnum FROM students MATCH ($num) AGAINST studentnum";
$namematch = mysql_query($qw) or die(mysql_error());
$nummatch = mysql_query($qw1) or die(mysql_error());

if (($namematch || $nummatch) == FALSE) {
die('Name or student number do not match those on record');
}

最佳答案

我相信您在 MATCH 子句中的参数是向后的。你有:

$qw = "SELECT name FROM students MATCH ($name) AGAINST name";

相反,它应该是:

$qw = "SELECT name FROM students MATCH (name) AGAINST $name";

换句话说,MATCH()与(参数)匹配,而不是相反。

http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html#function_match

关于php - mysql 匹配...通过引用字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23098113/

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