PHP, AJAX, HTML, MySQL, receive information from the database with the click of a button

I am trying to create a website that will introduce a person and their rating, but behind a password protected wall I can increase or decrease the score. I can make the button respond to ajax , but I cannot pass it to php and have php . strong> answer sql .

Ajax

<script>   
 $(document).ready(function () {
$('#next').click(function (e) {
    e.preventDefault();
    $.ajax({
        type: "GET",
        url: "a1.php",
        dataType: "html",
        success: function (msg) {
            if (msg.success) {
                $("#responsecontainer").html(msg);
            } else {
                alert("error");
            }
        }
    });
});
});
</script>

Honestly, I spent so much time on this problem with ajax flipping. I don’t even think I can understand what I was trying to do at this stage ... Sorry guys.

Php

<?php
$servername = "localhost";
$username = "test_db_usr";
$password = "123";
$dbname = "test_db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);


$sql = "SELECT id, name, points FROM points";
//how do I send this back to my html file?


$conn->close();
?>

, - " " MySQL. , PHP, , - !

, , , , ... .

, . Ill , , .

.

+4
3

U "id" , "" "", , click, $( "# action" ).val( "" ); : $( "# form" ). serialize(); Ajax-, SQL I.e. ..., .

0

$sql = "SELECT id, name, points FROM points";
//how do I send this back to my html file?

, AJAX GET, -

 $.ajax({
        type: "GET",
        url: "a1.php",
        dataType: "html",
        success: function (data) {
           console.log(data);
        }
    });

PHP- JSON,

return json_encode(array('success', data));

html

0
source

Source: https://habr.com/ru/post/1620665/


All Articles