WHERE OR子句中的mysql_error%s

时间:2015-11-11 01:05:40

标签: 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"这很好。我无法找到解决方案。

1 个答案:

答案 0 :(得分:0)

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

  

警告:sprintf():参数太少

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