2017-09-06 8 views
1

レコードを挿入して取得するためのプラグインを作成しました。レコードを保存すると、レコードはローカルホストから保存されていますが、オンラインサーバーで試してみると保存されません。ここに私がやろうとしていることがあります。Wordpressのプラグインデータがカスタムテーブルに挿入されていません

function data_custom_ajax(){  
     global $wpdb; 
     $tbl = "tripplan"; 
     $table_name=$wpdb->prefix . $tbl; 
     $custom_val = $_POST['text']; 
     $totaltime = $_COOKIE['totalduration']; 
     $totaldistance = $_COOKIE['totaldistance']; 
     $origin_address = $custom_val['originaddress']; 
     $end_address = $custom_val['destinationaddress']; 
     $waypoints = $custom_val['waypts']; 
      $wpdb->insert($table_name, 
          array(
          'startpoint' => $origin_address, 
          'endpoint' => $end_address, 
          'waypoints' => json_encode($waypoints), 
          'totaldistance' => $totaldistance, 
          'totalduration' => $totaltime 
          ), 
          array('%s','%s','%s','%f','%f') 
         ); 
      echo "data has been saved"; 

    } 
+0

あなたはこの関数を呼び出していますか? –

+0

私はログインしたユーザのためにそれを追加しました。ログインしていないユーザは 'add_action( 'wp_ajax_data_custom_ajax'、 'data_custom_ajax'); add_action( 'wp_ajax_nopriv_data_custom_ajax'、 'data_custom_ajax'); ' –

+0

はあなたのために働いていますか? –

答えて

0

読み取り、デバッグ、多くの後、私はこの問題を知りました。私のクッキーが正しく保存されませんでした。 localhost上で動作していたにもかかわらず、ウェブサイト上で動作していませんでした。これを読んだら[PHP cannot read javascript cookiesを保存した後に私のクッキーを変更した後。 私はこのようなCookieを設定して、それはそれが働いていたこのよう設定した後

document.cookie="cookiename="+value 

をworking-ていなかった -

document.cookie = 'cookiename='+value+'; path=/' 
1
function data_custom_ajax(){  
    global $wpdb; 
    $tbl = "tripplan"; 
    $table_name=$wpdb->prefix . $tbl; 
    $custom_val = $_POST['text']; 
    $totaltime = $_COOKIE['totalduration']; 
    $totaldistance = $_COOKIE['totaldistance']; 
    $origin_address = $custom_val['originaddress']; 
    $end_address = $custom_val['destinationaddress']; 
    $waypoints = $custom_val['waypts']; 

    $data = array(
     'startpoint' => $origin_address, 
     'endpoint' => $end_address, 
     'waypoints' => json_encode($waypoints), 
     'totaldistance' => $totaldistance, 
     'totalduration' => $totaltime 
     ) 

    $lastInsertedId = $wpdb->insert($table_name,$data); 


    if($lastInsertedId != '') 
    { 
     echo "data has been saved"; 
    }else{ 
     $wpdb->print_error(); 
    } 
     die(); 

} 
+0

レコードが保存されず、エラーが表示されません。上記を行った後に応答が来ない。エコーしません。 –

+0

これは、データベース接続が機能していないことを意味します。 –

+0

ですが、localhostから作業しています。私は何をすべきか。 –

関連する問題