I am having trouble displaying my two databases in my webpage. I have one database where the user can create a new "ticket" called "tickets" and when that ticket is marked as "Pending" it then moves the database entry to a new database table called "out_tickets". So on my index.php page i have like a dashboard view to display new "tickets" as well as to display the "Pending" tickets. But now I am struggling to display the "Pending" tickets results from the database on my index.php.
Here is my code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<style type="text/css">
.wrapper{
width: 0 auto;
margin: 0 auto;
}
.page-header h2{
margin-top: 0;
}
table tr td:last-child a{
margin-right: 15px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</p>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
</div>
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM tickets";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>Name</th>";
echo "<th>Address</th>";
echo "<th>Contact Details</th>";
echo "<th>Email</th>";
echo "<th>Job Type</th>";
echo "<th>Description</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['client_name'] . "</td>";
echo "<td>" . $row['client_address'] . "</td>";
echo "<td>" . $row['client_contact'] . "</td>";
echo "<td>" . $row['client_email'] . "</td>";
echo "<td>" . $row['client_jobtype'] . "</td>";
echo "<td>" . $row['client_description'] . "</td>";
echo "<td>";
echo "<a href='read.php?id=". $row['id'] ."' title='View Task' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". $row['id'] ."' title='Update Task' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Task' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "<a href='pending.php?id=". $row['id'] ."' title='Task Pending' data-toggle='tooltip'><span class='glyphicon glyphicon-time'></span></a>";
echo "<a href='complete.php?id=". $row['id'] ."' title='Mark Complete' data-toggle='tooltip'><span class='glyphicon glyphicon-ok'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</div>
</div>
</div>
</div>
<h1 style="font-size:25px;
background-color:darkgray;
border:2px solid black;
text-align:center">
Outstanding Tasks
</h1>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<style type="text/css">
.wrapper{
width: 0 auto;
margin: 0 auto;
}
.page-header h2{
margin-top: 0;
}
table tr td:last-child a{
margin-right: 15px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</p>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
</div>
<?php
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM out_tickets";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>Name</th>";
echo "<th>Address</th>";
echo "<th>Contact Details</th>";
echo "<th>Email</th>";
echo "<th>Job Type</th>";
echo "<th>Description</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['client_name'] . "</td>";
echo "<td>" . $row['client_address'] . "</td>";
echo "<td>" . $row['client_contact'] . "</td>";
echo "<td>" . $row['client_email'] . "</td>";
echo "<td>" . $row['client_jobtype'] . "</td>";
echo "<td>" . $row['client_description'] . "</td>";
echo "<td>";
echo "<a href='read.php?id=". $row['id'] ."' title='View Task' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". $row['id'] ."' title='Update Task' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Task' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "<a href='pending.php?id=". $row['id'] ."' title='Task Pending' data-toggle='tooltip'><span class='glyphicon glyphicon-time'></span></a>";
echo "<a href='complete.php?id=". $row['id'] ."' title='Mark Complete' data-toggle='tooltip'><span class='glyphicon glyphicon-ok'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found. </em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " .
mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</div>
</div>
</div>
</div>
As you can see the first $sql = "SELECT * FROM tickets";
works, but this one doesn't $sql = "SELECT * FROM out_tickets";
I have these two databases in MySQL and can see the data in them from PHPmyAdmin
This is the error I am getting:
Warning: mysqli_query(): Couldn't fetch mysqli in
C:\index.php on line 211
Warning: mysqli_error(): Couldn't fetch mysqli in
C:\index.php on line 254
ERROR: Could not able to execute SELECT * FROM out_tickets.
Warning: mysqli_close(): Couldn't fetch mysqli in
C:\index.php on line 258