그것은 귀하의 질문에 대답하기 위해, 귀하의 질문을 업데이트하고이 코드를 추가 할
을 시도 당신이 가지고있는 코드를 제공하지 않고 귀하의 질문에 대답하기 어렵다 당신이 사용하고 있다고 말했기 때문에 jquery, ajax and php
을 사용하여 데이터베이스에 textarea
값을 저장한다는 목표를 달성하는 데 사용할 수있는 간단한 구조가 있습니다. 난 당신이, 임 당신의 저장 텍스트와 스타일에 대한 아마 일부 HTML 태그를 가정 한 데이터의 유형을 잘 모릅니다
당신의 HTML :
<textarea id='myData'>Some text here I want to save</textarea>
<button type='button' id='saveData'>Save</button>
당신의 jQuery로 AJAX :
<script>
$(document).on("click","#saveData", function(){
var myData = $("#myData").text();
$.ajax({
url: 'pathToYourPhp file that will receive your post data and will store it to the database',
type: 'POST', /* Since you are Passing data */
dataType: 'json', /* this is the returned value after saving, you can use text/json/html */
data: { 'myData': myData }, /* This is the data you are about to store, you can access it on your pathToYourPhp file by using $_POST['myData'], */,
success: function(data){
alert('Save'); /* you put here what you want to do after saving */
}
});
});
</script>
당신의 게시 데이터를 처리 할 PHP 파일 :
이것은 완료되지 않았지만 파일 구조는
입니다. 16,
$myData = $_POST['myData'];
여기에 연결 문자열
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO yourTable (`fieldName`) VALUES($myData)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
나는이 문제의 코드를 포함 할 수 없습니다 죄송합니다. –