0

Does anyone see anything wrong with what I am doing here? I haven't worked with the database expressions in WP yet. All of my code runs except when I start to try to add items to tables I have created in the WP database. Any info would be greatly appreciated. To me it seems that this syntax is correct and should run.

$wpdb->insert($wpdb->prefix . 'venue', array('event_id' => $event_id, 
                                    'event_date' => $event_date, 
                                    'venue_name' => $venue_name, 
                                    'venue_city' => $venue_city, 
                                    'ticket_url' => $ticket_url, 
                                    'event_url' => $event_url), 
                                array(%d, %s, %s, %s, %s, %s) );

Many thanks.

UPDATE!: There seems to be an issue connecting to the WP database from within an AJAX call. I am using jQuery to call a php file and trying this within the PHP file. This does not seem to work as maybe the $wpdb class is outside of the scope?

3
  • What does it return? Wrap it in a var_dump() to get more details. Or turn on WP_DEBUG in your config file. Commented Oct 27, 2010 at 22:27
  • @Jason, I haven't had any luck from either. Debug doesn't seem to report any errors and var_dump produces nothing. It seems that everything will run with this line commented out but as soon as I comment it in nothing works. Commented Oct 27, 2010 at 22:33
  • Please see above update. Commented Oct 27, 2010 at 22:41

2 Answers 2

1

The values in the array containing the fieldtypes should be between ' and '.

So that would become:

array('%d', '%s', '%s', '%s', '%s', '%s')

Instead of:

array(%d, %s, %s, %s, %s, %s)

Hope this can be of help for others having this problem.

Sign up to request clarification or add additional context in comments.

Comments

0
if(!isset($wpdb)){
$wpdb = new wpdb("user","pass","mydb",localhost);
}

Try it with this code on top?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.