Showing mysql rows content in html table using php

im new here and i have a question, i looked for the solution everywhere and i still cant manage to solve this.

I want to show the results of the SELECT statement (in php) in a table (html) using JS. Here is the code of these 3 files:

HTML file

    <html>
<head>
    <meta charset="UTF-8"/>
    <script src="C:UsersMarianoDesktopjsonmasmasmasdatos.js"></script>
    <script src="select.js" type="text"javascript"></script>
</head>
<body>
<button id="button"> Mostrar </button>
<br>
<input type="text" id="id" />
<div id="content"></div>
</body>
</html>

PHP file

<?php
$link=mysqli_connect("folder.es", "user_tienda","A*7I8qpg5","pool_tiendas");

if (mysqli_connect_errno() )
    echo "Fallo en la conexion con mysql" .mysqli_connect_error();

$action=$_POST["action"];
if ($action=="showroom") {
    $query = "SELECT cod, nmbre, drccn from tienda";
    $show = mysqli_query($link, $query) or die ("error");
    echo "<table border='2px'><tr><td>cod</td><td>nmbre</td><td>drccn</td</tr>";
    while ($row = mysqli_fetch_array($show)) {

        echo "<tr><td>" .$row['cod']."</td><td>".$row['nmbre']."</td><td>".$row['drccn']."</td></tr>";
    }
    echo "</table>";
}
?>

JS file

$(document).ready(function(){
    $("#button").click(function () {

        function show_all() {
            $.ajax({
                type: "POST",
                url: "select.php",
                data:{action:"showroom"},
                success: function (data) {
                    $("#id").hide();
                    $("#content").html(data);
                }
            });
        }

        show_all();
    });
});

The problem is when i click the button to show the content nothing happens.

need some help from you ! Thanks for reading!

*The Select statemnt is correct, in Mysql font i can see the results of the SELECT statement.

*I also checked the mozilla “console” but nothing appears there

*Sorry for my bad english if its bad 😉


Source: mysql

Leave a Reply