2017-10-01 2 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로 변경하고, 형태는 F5 값 입력 필드에서 데이터베이스에서 사라지면 값 필드
  3. 의 DB에 저장되는 값 도시 25
  4. 을 submited된다.

    enter image description here

    내가 잘 이해한다면

    enter image description here

    enter image description here

    SQL number taken from Database

, 나는 어떻게 든 삭제하지 않고 데이터베이스에 데이터를 저장하는 페이지 자체를 리디렉션해야합니다.

누구나 프로그램을 올바르게 작성하는 방법을 알고 있습니까?

미리 감사드립니다.

답변

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가 제출/게시 된 경우에만 사용자 메타를 업데이트합니다.

관련 문제