gpt4 book ai didi

php - WHERE OR 子句中出现 mysql_error %s

转载 作者:行者123 更新时间:2023-11-29 21:50:58 25 4
gpt4 key购买 nike

$colname_rs_txtSearchFirstname = $_POST['txt_search'];    
$sql_rs_txtSearch = sprintf("SELECT * FROM staffstu WHERE lastname = %s OR
firstname = %s ORDER BY lastname, firstname ASC",
GetSQLValueString($colname_rs_txtSearchFirstname, "text",
$colname_rs_txtSearchFirstname, "text"));

它总是给出

mysql_error

如果我不使用“sprintf”,那就工作正常。我找不到解决方案。

最佳答案

您缺少第二个%s的参数!您应该收到以下 PHP 警告

Warning: sprintf(): Too few arguments

$colname_rs_txtSearchFirstname = $_POST['txt_search'];    
$sql_rs_txtSearch = sprintf("SELECT * FROM staffstu WHERE lastname = %s OR
firstname = %s ORDER BY lastname, firstname ASC",
GetSQLValueString($colname_rs_txtSearchFirstname, "text",
$colname_rs_txtSearchFirstname, "text"), <missing_param>);

我想你想要这个(检查它是否正确)

$colname_rs_txtSearchFirstname = $_POST['txt_search'];    
$sql_rs_txtSearch = sprintf("SELECT * FROM staffstu WHERE lastname = '%s' OR
firstname = '%s' ORDER BY lastname, firstname ASC",
GetSQLValueString($colname_rs_txtSearchFirstname, "text"),
GetSQLValueString($colname_rs_txtSearchLastname, "text"));

您不应该使用 mysql_* 函数。更多信息请点击:Why shouldn't I use mysql_* functions in PHP?

关于php - WHERE OR 子句中出现 mysql_error %s,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33642587/

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