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

标签 php mysql

$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/

相关文章:

mysql - 我不知道为什么在 MySql 中完全连接时会出现此错误

php - MySQL SELECT 以 PK 作为结果集的键

Mysql 5.5 自动创建每月分区

javascript - AJAX 重定向

PHP:为什么 exec() 不返回输出?

php - 如何从 Survey Monkey 调查中获取受访者 ID?

mysql - SQL 连接。从三个表中获取数据

Java - XLSX 解析和数据库导出

php - 动态复选框验证

php - 为二维数组赋值