I’m trying to put together a plugin script that takes a range of values from various locations including csv and strings them together to update existing rows in my db. It’s designed to update prices for WP Ecommerce, when you start with just a sku and the new price. The first query retrieves the additional info I need from the db, and the string puts the data in the correct order.
I’ve got the values in a string ready to import. But I keep getting the error in the title: “wrong parameter count for mysql_query()”. Can anyone help me out? Have I done something fundamentally wrong here?
$result = mysql_query("SELECT * FROM `wp_postmeta` WHERE `post_id` = (SELECT `post_id` FROM `wp_postmeta` WHERE `meta_value` = '$var') AND `meta_key` = '_wpsc_price'") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
//Collates all the info for the line of data we need...
$my_string = ($row['meta_id'].$row['post_id'].$row['meta_key'].$data[$index-1]);
global $wpdb;
$update = mysql_query("REPLACE TABLE 'wp_postmeta' VALUES ($my_string)",
mysql_real_escape_string($meta_id),
mysql_real_escape_string($post_id),
mysql_real_escape_string($meta_key),
mysql_real_escape_string($meta_value));
}
So really your query goes
changing the name of datafield to whichever it should be
The
mysql
extension is deprecated and its use is strongly discouraged. In addition,mysql_query()
does not accept query placeholders at all, it accepts one or two parameters only â query string and optional connection handle. In addition, you’re building a very weird value in$my_string
which then you just dump into your query string. It is hard for me to even imagine what you’re trying to accomplish by that.PHP’s mysql_query is expecting one or two parameters. What you want to do is something like
That code is untested – just so you get the general idea.