Rookie coder here trying to learn from mistakes. :)
I have three files (jquery.js, php.php and html.html).
I am trying to fetch information from mySQL database name trial1
. It has only one table called Score_Sheet
.
Below is the code for html.html
<!DOCTYPE html>
<html>
<head>
<script type="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src= "jquery.js" type = "text/javascript"></script>
</head>
<body>
<button id = "button"> Click to see value from SQL table</button>
<div id= "content"></div>
</body>
<html>
Below is the code for php.php
$link = mysqli_connect("localhost","root","","trial1");
$query = "SELECT * FROM Score_Sheet";
$show = mysqli_query($link, $query) or die ("Error");
echo "<table><tr><td>ID</td><td>UserID</td><td>Score</td></tr>";
while ($row = mysqli_fetch_array($show)){
echo "<tr><td>" . $row['ID'] . "</td><td>" . $row['UserID'] . "</td><td>" . $row['Score'] . "</td></tr>";
}
echo "</table>";
}
Below is the code for jquery.js
$(document).ready(function(){
$("#button").click(function(){
function show_all(){
$.ajax({
type = "POST",
url = "php.php",
success: function (data){
$("#content").html(data);
}
});
}
// show_all();
});
});