8

I have an sql query like this

if (isset($_POST['no_peserta_mhs_2015'])) {
$colname_rec_mhs_2015 = $_POST['no_peserta_mhs_2015'];
}
mysql_select_db($database_connect, $connect);
$query_rec_mhs_2015 = sprintf("SELECT * FROM mhs_2015 WHERE no_peserta_mhs_2015 = %s or nama_mhs_2015 like %s ", GetSQLValueString($colname_rec_mhs_2015, "text"));

But I get this error

Warning: sprintf(): Too few arguments in C:\xampp\htdocs\gugus_2015\index.php on line 39 Query was empty

I don't know what's wrong.

eniac05
  • 477
  • 4
  • 10
  • 23

1 Answers1

17

You have two %s items in the string but only one parameter supplied after the string. For each '%' item in the format string it expects a matching parameter after the string to use to find in the value.

like this:

sprintf("item 1: %s, item 2: %s", "item1", "item2");

what you have is like:

sprintf("item 1: %s, item 2: %s", "item1");

so there is no entry for the item 2 string to match

Paul Coldrey
  • 1,389
  • 11
  • 20
  • 8
    It can mean also that you got unescaped %. Like in: http://stackoverflow.com/questions/3666734/php-sprintf-escaping – suz Apr 12 '17 at 14:02
  • 2
    Thanks @suz my issue was the escaping.. and I didn't know you used another `%` to do that. The answer should be updated to include it. – n1nsa1d00 Mar 22 '18 at 18:10