I have a very basic webpage, which I am trying to connect to my MariaDB database with PHP and display the data in a table. First of all, I know I can connect to my database with Python using the following code.
#mariadb_connection = mariadb.connect(user='root', password='pwd', database='customers')
#cursor = mariadb_connection.cursor()
#cursor.execute("SELECT * from customer_info")
#data = cursor.fetchall()
#cursor.close()
This returns my data no problem. Now my php/html is as follows
<?php
$connect = mysqli_connect("localhost","root","iotindustries","customers");
$query = "SELECT * FROM cusomter_info";
$result = mysqli_query($connect, $query);
?>
<!DOCTYPRE html>
<html>
<head>
<title>Datatable ting</title>
<link rel ="stylesheet" href="/static/css/bootstrap.css">
<link rel ="stylesheet" href="/static/css/dataTables.bootstrap.css">
<link rel ="stylesheet" href="/static/css/jquery.dataTables.min.css">
</head>
<body>
<table id="mytable" class"table table-striped table-bodered">
<thead>
<tr>
<td>Name</td>
<td>Address</td>
<td>PPL</td>
</tr>
</thead>
<?php
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td>'.$row["name"].'</td>
<td>'.$row["address"].'</td>
<td>'.$row["PPL"].'</td>
</tr>
';
}
?>
</table>
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.js"></script>
<script type="text/javascript" src="/static/js/jquery.dataTables.js">
</script>
<script type="text/javascript"
src="/static/js/jquery.dataTables.min.js"></script>
<script type="text/javascript"
src="/static/js/dataTables.bootstrap4.min.js"></script>
<script type="text/javascript" src="/static/js/script.js"></script>
<script>
$(document).ready(function() {
var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'tr', function () {
$(this).toggleClass('selected');
} );
$('#button').click( function () {
alert( table.rows('.selected').data().length +' row(s) selected' );
} );
} );
</script>
</body>
</html>
When running the html in my browser all I see is the following. It's like the php starts to work and then stops near the end and doesn't successfully bring my data in to my website. Any ideas why this isnt working?
'; } ?>
Name Address PPL
'.$row["name"].' '.$row["address"].' '.$row["PPL"].'
I am essentially following this tutorial with my database. I have copied it row for row but do no get the same results. https://www.youtube.com/watch?v=2RGlzZyS1_0