사용자가 제출 버튼을 클릭하면 mysql에 5 가지 형식의 데이터를 입력 할 수있었습니다.클릭하면 mysql을 테이블로 가져 오기
이제 사용자가 다른 버튼을 클릭 할 때 테이블에 데이터를 표시하려고합니다. Ajax와 PHP를 사용해야한다는 것을 알고 있지만, 나에게 명확한 예제를 찾을 수 없었다.
내 코드의 일부가 아래에 있습니다. 나는 자바 스크립트와 PHP를 포함하지 않았다. 나는 폼 데이터를 데이터베이스에 게시하는 데 사용했다. 이해가 도움이된다면 추가 할 수 있습니다.
input.html
<div class="container">
<form action="vocab_input.php" method="post" id="input_form">
<label>Word:</label>
<input type="text" name='word'>
<label>POS:</label>
<input type="text" name='pos'>
<label>Translation:</label>
<input type="text" name='trans'>
<label>Definition:</label>
<input type="text" name='definition'>
<label>Sentence:</label>
<input type="text" name='sen'>
<input type="submit">
</form>
</div>
<div class="btn-group btn-group-justified" role="group" aria-label="..." style="margin-top: 50px;">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default" id="list">Vocab List</button>
</div>
</div>
<-- I want the table displayed here when user clicks the list button -->
get_input.js
$(function() {
$('#list').on('click', function(e) {
var data = $("#list :input").serialize();
$.ajax({
type: "GET",
url: "get_input.php",
data: data,
});
e.preventDefault();
});
});
get_input.php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM user_input";
$result = $conn->query($sql);
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
foreach($row as $field) {
echo '<td>' . htmlspecialchars($field) . '</td>';
}
echo '</tr>';
}
$conn->close();
?>
http://stackoverflow.com/questions/42627922/how-to-search-value-from-input-by-mysqli-in-database/42628959#42628959 –
일부 문서보기 http://stackoverflow.com/ server/t- = 201704122003399486055 반환 된 데이터를 처리하는 데 사용되는'.success' 함수가 있음을 참고하십시오. – RiggsFolly
당신은 'mysql_fetch_array'라는 APIS를 섞어 쓰고 있습니다. 그냥 오타가 아닙니까? – hassan