문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

Try it with this code on top?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top