Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

PHP Notice: Object of class WP_Error could not be converted to int in /var/www/vhosts/hayhauler.co/httpdocs/wp-includes/functions.php on line 2568, referer: http://hayhauler.co/

I'm not even sure where to start with this or the right question to ask. I know that it is preventing me from posting some information into a database using this:

$wpdb->query($wpdb->prepare(
  "
    INSERT INTO $wpdb->quotes
    (user_ID,origin,destination,broker_ID,quote_ID,estimatedship)
    VALUES (%d,%s,%s,%d,%s,%s)
  ",
  $user_id,
  $origin,
  $destination,
  $brokerID,
  $brokerID.'-'.genRandomString(),
  $estimatedship
));

And this error follows it:

mysql_real_escape_string() expects parameter 1 to be string, object given in /var/www/vhosts/hayhauler.co/httpdocs/wp-includes/wp-db.php on line 789, referer: http://hayhauler.co/

Any help or direction would be greatly appreciated.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

One of the variables you're trying to pass into wpdb::prepare is a WP_Error object. WP_Error's are like exceptions mixed with return codes: some functions in the WordPress API return WP_Error objects to tell you something went wrong (like get_terms).

We'll need to see more of your code to be more specific, but you can test for them with the function is_wp_error. So, let's say $brokerID was causing the issue:

<?php
$brokerID = some_function_that_gets_broker_id();

if(is_wp_error($brokerID))
{
    // do stuff to fix it
}
else
{
    // Your original code goes here.
}
share|improve this answer
    
Wow. This form of error checking is a whole new word for me. Thanks. It helped point me in the right direction. Basically, $estimatedship didn't have a corresponding column in the table. I'm just not sure why WP didn't throw a more specific error into the window since I had define('WP_DEBUG', true); –  Greg Wiley Sep 25 '12 at 3:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.