[wp-hackers] Percent in $wpdb->prepare()?
nb at nikolay.bg
Tue Feb 3 21:44:34 GMT 2009
On Tue, Feb 3, 2009 at 23:37, Jobjörn Folkesson <jobjorn at gmail.com> wrote:
> Hello everyone,
> I am slowly learning to build plugins for BuddyPress, and I love the
> WordPress platform. One of the many great things it provides is that nifty
> database input sanitization function provided in $wpdb - noone likes a Bobby
> Tables incident.
> However, when I try to use it to add a row where one cell contains the
> percent sign ("%"), nothing happens. What am I doing wrong?
> $wpdb->query($wpdb->prepare("INSERT INTO testtable(test) VALUES ('71% of the
> surface of the Earth is water.')"));
prepare() expects a sprintf() format string, in which the % is used to
prefix placeholder types. You can use a literal % by prepending it
with another %: %%.
More information about the wp-hackers