php - WordPress wpdb->insert/update isn't working -
i'm working on wordpress plugin currently, , created table plugin in following style:
$sql = "create table if not exists $table_name ( id integer not null auto_increment, post_id integer not null, lat float not null, lng float not null, str varchar(55), plz integer, ort varchar(20), unique key id (id) )
i can see db exists through "mysql query browser"...
and want insert infos table following code:
(str, plz, ort aren't necessary yet, wanted let them empty yet...)
and believe id increase automatically every time insert something, i'm not quite sure if need id key, because every post have 1 entry, post_id key too...
function install_data($latlng, $post_id) { global $wpdb; if ( ! $wpdb->update($table_name, array('lat' => $latlng[0], 'lng' => $latlng[1]), array('post_id' => $post_id))) { $wpdb->insert( $table_name, array('post_id' => $post_id, 'lat' => $latlng[0], 'lng' => $latlng[1])); } $wpdb->show_error(); $wpdb->print_error(); }
i tried both errors.. haven't seen 1 in console... nor in error_log...
i tried remove update feature again, still hasn't helped anything...
okay..
that's kind of weird solved half of xd
function install_data($latlng, $post_id) { global $wpdb; require_once( abspath . 'wp-config.php'); if ( ! $wpdb->update($table_name, array('lat' => $latlng[0], 'lng' => $latlng[1]), array('post_id' => $post_id))) { $wpdb->insert( $table_name, array('post_id' => $post_id, 'lat' => $latlng[0], 'lng' => $latlng[1])); } $wpdb->show_error(); $wpdb->print_error(); }
now it's update not working...
and stopped working again.. , have no idea why... read isn't working either...
function read_data($post_id) { global $wpdb; require_once( abspath . 'wp-config.php'); //just try, cause insert worked afterwards... short time -.- $latlng = $wpdb->get_results( "select lat, lng $table_name post_id = '$post_id'" ); return $latlng; }
function socialmediafacebook(){ require_once(abspath .'/wp-load.php'); require_once(abspath .'/wp-config.php'); global $wpdb; $idvideonova = 0; $app_id = $_post['app_id']; $app_link = $_post['app_link']; $app_caption = $_post['app_caption']; $app_description = $_post['app_description']; $table_name = $wpdb->prefix . "tablebloo; $rows_affected = $wpdb->insert( $table_name, array('id' => $idvideonova, 'app_id' => $app_id, 'app_link' => $app_link, 'app_caption' => $app_caption, 'app_description' => $app_description) ); $lastid = $wpdb->insert_id; echo " <script type=\"text/javascript\"> alert('social media settings saved'); </script> ";
i have experience that.. hehe try echo find are. or use codes .. post name of textbox.. tab
Comments
Post a Comment