akash614
Posts: 47
Joined: Tue Dec 05, 2017 2:48 am

Can't view mysql data on to a html page

Sun Apr 21, 2019 1:55 am

Hi guys i have been working on a project and everything is working fine but when i click on html navigation bar to view the data i get nothing in it but just shows like there are no entries in it but i got code to work on my pc running XAMPP but i can't get it to run on raspberry pi here is the code

Code: Select all

<?php
mysql_connect('localhost','root','');
mysql_select_db('database');
$query="select * from log_tbl";
$result=mysql_query($query);
?>
<!DOCTYPE Html>
<html>
<title>View-Entries</title>
<head>
<style>
  table {
   border-collapse: collapse;
   width: 100%;
   color: White;
   font-family: monospace;
   font-size: 25px;
   text-align: left;
     } 
  th {
   background-color: White;
   color: DodgerBLue;
    }
  tr:nth-child(even) {background-color: Dodgerblue}
 </style>
</head> 
<body bgcolor=DodgerBlue>
<ul class="navbar">
  <li><a href="Main.html">Back To Home</a>
</ul>
<h1 align=center style="color:LightYellow;">Entries are Viewed as following:</h1>
<table>
<t>
<th>UID</th>
<th>Date and Time</th>
<th>Gate Accessed</th>
<th>Action</th>
</t>
<?php
while($rows=mysql_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $rows['serial_no']; ?></td>
<td><?php echo $rows['date_stamp']; ?></td>
<td><?php echo $rows['reader']; ?></td>
<td><?php echo $rows['action']; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>

fbe
Posts: 649
Joined: Thu Aug 17, 2017 9:08 pm

Re: Can't view mysql data on to a html page

Sun Apr 21, 2019 5:44 am

Look into /var/log/apache2/error.log.

User avatar
DougieLawson
Posts: 40204
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can't view mysql data on to a html page

Sun Apr 21, 2019 6:20 am

mysql_connect() is removed in PHP V7.0

https://www.php.net/manual/en/function. ... onnect.php

Try this version

Code: Select all

<?php
$con = new mysqli("localhost", "myrestrictedSQLuser", "non-blank-password", "database_name_here");

#
# Don't use SELECT * it will bite you later
#
#$query="select * from log_tbl";

$query="SELECT serial_no, date_stamp, reader, action FROM log_tbl;";

$result = mysqli_query($con, $query);
?>
<!DOCTYPE Html>
<html>
<title>View-Entries</title>
<head>
<style>
  table {
   border-collapse: collapse;
   width: 100%;
   color: White;
   font-family: monospace;
   font-size: 25px;
   text-align: left;
     }
  th {
   background-color: White;
   color: DodgerBLue;
    }
  tr:nth-child(even) {background-color: Dodgerblue}
 </style>
</head>
<body bgcolor=DodgerBlue>
<ul class="navbar">
  <li><a href="Main.html">Back To Home</a>
</ul>
<h1 align=center style="color:LightYellow;">Entries are Viewed as following:</h1>
<table>
<t>
<th>UID</th>
<th>Date and Time</th>
<th>Gate Accessed</th>
<th>Action</th>
</t>
<?php
while($rows=mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $rows['serial_no']; ?></td>
<td><?php echo $rows['date_stamp']; ?></td>
<td><?php echo $rows['reader']; ?></td>
<td><?php echo $rows['action']; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
BTW, don't use root for PHP based SQL as that is a security hole. Create a specific ID which only has access to the tables you need for the function you're writing. Also ALWAYS select just the columns your program is interested in or it will bite you later.
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

akash614
Posts: 47
Joined: Tue Dec 05, 2017 2:48 am

Re: Can't view mysql data on to a html page

Sun Apr 21, 2019 3:09 pm

DougieLawson wrote:
Sun Apr 21, 2019 6:20 am
mysql_connect() is removed in PHP V7.0

https://www.php.net/manual/en/function. ... onnect.php

Try this version

Code: Select all

<?php
$con = new mysqli("localhost", "myrestrictedSQLuser", "non-blank-password", "database_name_here");

#
# Don't use SELECT * it will bite you later
#
#$query="select * from log_tbl";

$query="SELECT serial_no, date_stamp, reader, action FROM log_tbl;";

$result = mysqli_query($con, $query);
?>
<!DOCTYPE Html>
<html>
<title>View-Entries</title>
<head>
<style>
  table {
   border-collapse: collapse;
   width: 100%;
   color: White;
   font-family: monospace;
   font-size: 25px;
   text-align: left;
     }
  th {
   background-color: White;
   color: DodgerBLue;
    }
  tr:nth-child(even) {background-color: Dodgerblue}
 </style>
</head>
<body bgcolor=DodgerBlue>
<ul class="navbar">
  <li><a href="Main.html">Back To Home</a>
</ul>
<h1 align=center style="color:LightYellow;">Entries are Viewed as following:</h1>
<table>
<t>
<th>UID</th>
<th>Date and Time</th>
<th>Gate Accessed</th>
<th>Action</th>
</t>
<?php
while($rows=mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $rows['serial_no']; ?></td>
<td><?php echo $rows['date_stamp']; ?></td>
<td><?php echo $rows['reader']; ?></td>
<td><?php echo $rows['action']; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
BTW, don't use root for PHP based SQL as that is a security hole. Create a specific ID which only has access to the tables you need for the function you're writing. Also ALWAYS select just the columns your program is interested in or it will bite you later.


Thanks man your piece of code worked i tried before mysqli but no luck so thanks for help for help and thanks everyone

Return to “Networking and servers”