0

Please help me with this.

I got this error:

Missing argument 2 for wpdb::prepare()

For this line:

$myrows = $wpdb->get_results($wpdb->prepare("SELECT name, term_id
                                             FROM wp_categoryindex
                                             WHERE alpha IN ('0','1','2','3','4','5','6','7','8','9')")); 

Thank you!

Logan Wayne
  • 5,884
  • 15
  • 29
  • 47
user2151960
  • 175
  • 1
  • 1
  • 11
  • possible duplicate of [How can I prevent SQL-injection in PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – dingo_d Sep 15 '15 at 05:43
  • Take a look at these: http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks and http://codex.wordpress.org/Data_Validation#Database – dingo_d Sep 15 '15 at 05:43

2 Answers2

2

Why are you using both functions get_results() and prepare()? Do you have idea about any of these functions?

I think this may be useful for you. Can you please try this:

$myrows = $wpdb->get_results("SELECT name, term_id
                                             FROM wp_categoryindex
                                             WHERE alpha IN ('0','1','2','3','4','5','6','7','8','9')");

Or

$myrows = $wpdb->prepare("SELECT name, term_id
                                             FROM wp_categoryindex
                                             WHERE alpha IN %s", "('0','1','2','3','4','5','6','7','8','9')");
$getData = $wpdb->get_var($myrows);
dingo_d
  • 9,839
  • 10
  • 62
  • 102
0

Well, after a quick RT*M one finds that your missing second argument pointed out by the system should be parameters supporting sprint()-like placeholders, which you don't have. So you need to look over the documentation for the method and consider whether you wish to use the substitution capabilities or use a different method that doesn't require those, e.g, query().

Parameters

  • $query (string) (Required) Query statement with sprintf()-like placeholders

  • $args (array|mixed) (Required) The array of variables to substitute into the query's placeholders if being called like http://php.net/vsprintf vsprintf(), or the first variable to substitute into the query's placeholders if being called like http://php.net/sprintf sprintf().

  • $args,... (mixed) (Required) further variables to substitute into the query's placeholders if being called like http://php.net/sprintf sprintf().

Shawn Mehan
  • 4,274
  • 9
  • 28
  • 48