환경설정 여분필드값 저장 채택완료

2년 전 조회 4,285

$config['cf_1'] 값을 환경설정 여분필드에서 입력하려는건 아니고
메인화면에서 저장하는게 가능할지요? 아래처럼 ajax시도중인데요.
하려고 하는것은 보시다시피 radio버튼 선택후 save할경우 

$config['cf_1'] 값에 선택된 value값을 저장하고자 합니다. 

조언 바랍니다. ^^


index.php

Copy
<form id="configForm">
  <input type="radio" name="cf_1" value="1" checked> Option 1
  <input type="radio" name="cf_1" value="2"> Option 2
  <button id="saveButton" type="button">Save</button>
</form>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>


<script>
$(document).ready(function() {
  $("#saveButton").click(function() {
    var formData = $("#configForm").serialize();
    
    $.ajax({
      url: "update_config.php",
      type: "POST",
      data: formData,
      success: function(response) {
        alert("완료");
      },
      error: function(xhr, status, error) {
        alert("실패: " + error);
      }
    });
  });
});
</script>

같은 위치에 update_config.php

Copy
<?php
include_once("./_common.php");


function updateConfigValue($name, $value) {
  global $config;
  $config[$name] = $value;
  sql_query("update $g5[config_table] set cf_1='$value' where cf_id='$name'");
}


if ($_SERVER['REQUEST_METHOD'] === 'POST') {

  if (isset($_POST['cf_1'])) {
    updateConfigValue('cf_1', $_POST['cf_1']);
  }


  header('Location: index.php');
  exit();
}

?>

답변 2개

채택된 답변
+20 포인트
sql_query("update $g5[config_table] set cf_1='$value'"); 로 하시면 될거같습니다.
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

감사합니다. 이렇게 진행해보는 중인데 경로 문젠가 싶어서. 이것 저것 하는중입니다.

댓글을 작성하려면 로그인이 필요합니다.

g5_config 테이블에 cf_id라는 필드는 없습니다.

where 조건절을 살펴보세요.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

아 그렇네요. 감사합니다.

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고