2017-10-01 3 views
1

私はWordpress update_user_metaに関する基本的な質問があります。私はfromを書き込もうとしています。これはユーザーが編集することができます。問題は、送信されたフォームからの値がデータベースに保存されますが、ページのリロードがDBから値が削除された後です。WP - ユーザー自身によるユーザーメタの更新 - 保存に伴う問題

コードは次のとおり

<?php 
$current_user_id = get_current_user_id(); 
echo $user->schoolstudentscount; 
?> 
<form name="Students Count" action="" method="POST"> 
<fieldset> 
<input type="text" id="count_of_students" name="count_of_students"/> 
</fieldset> 
<button type="submit">Save</button> 
</form> 
<?php 
$low_price = $_POST['count_of_students']; 
update_user_meta($current_user->ID, 'schoolstudentscount', $low_price); 
?> 

ベター説明:番号35をDBから取得され

  1. シンプルな形。
  2. 値は25に変更され、フォームが
  3. 値25をsubmitedれるDBに格納され、F5値が入力フィールドから、データベースから消失した後、値フィールド
  4. に示されています。

SQL number taken from Database

enter image description here

enter image description here

enter image description here

私はよく理解していれば、私は何とか消去されず、データベース内のデータを格納するページ自体をリダイレクトする必要があります。

誰でもプログラムを正しく書き込む方法を知っていますか?

ありがとうございます。

答えて

0
if (isset($_POST['count_of_students'])){ 
    $low_price = $_POST['count_of_students']; 
    update_user_meta($current_user->ID, 'schoolstudentscount', $low_price); 
} 

これは、count_of_studentsが送信/投稿された場​​合にのみユーザーメタを更新します。

関連する問題