I create pdf in php using FPDF it's always showing blank documents. its size only 1.60kb. i fetching mysql data and want to admit card.
I create pdf in php using FPDF it's always showing blank documents. its size only 1.60kb. i fetching mysql data and want to admit card.
(i) admitcard.php
<div class="container">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#viewapp">View Applications</a></li>
<li>Logout</li>
</ul>
<div class="tab-content">
<div id="viewapp" class="tab-pane fade in active">
<?php
$rs1 = mysqli_query($con,"select * from demodata");
echo '<table class="table table-striped" id="tblData">';
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>NAME</th>";
echo "<th>DATE OF BIRTH</th>";
echo "<th>EMAIL ID</th>";
echo "<th>CONTACT NO.</th>";
echo "<th>SIGNUP DATE</th>";
echo "<tr>";
echo "</thead>";
echo "<tbody>";
while($ar = mysqli_fetch_array($rs1))
{
echo "<tr>";
echo "<td><a href='viewform.php?id=".$ar[0]."'>" . $ar[0] . "</a></td>";
echo "<td>" . $ar[3] . "</td>";
echo "<td>" . $ar[2] . "</td>";
echo "<td>" . $ar[4] . "</td>";
echo "<td>" . $ar[5] . "</td>";
echo "<td>" . $ar[6] . "</td>";
echo "<td> <a target='_blank' href='generate_pdf.php?id=".$ar[0]."'>
<input type='button' value='PDF' name='adcard' class='toggle btn btn-primary'> </a></td>";
echo "</tbody>";
echo "</table>";
?>
</div>
</div>
(ii) genrate_pdf.php
<?php
require("fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$a=$_POST["add"];
$pdf->Cell(40,10,$a);
$pdf->Output();
?>
Related
When I click on a link to redirect to 'single_assignment_page.php' it is not showing the content of this page but it is showing the content of 'index.php'. That's something I don't want but in the URL bar it is showing the right URL that I want. I'm working with my own theme in WordPress.
front-page.php with the link at the bottom
<div class="container">
<h2 class="title-section" >Opdrachten</h2>
<p>Hieronder staan de opdrachten vermeld die zijn ingezonden door bedrijven en particulieren. Het is gesorteerd van nieuw naar oud. De opdrachten zijn alleen te zien voor ingelogde gebruikers.</p>
<?php
$results = $wpdb->get_results( "SELECT id, voornaam, achternaam, bedrijfsnaam, telefoonnummer, emailadres, titel_opdracht, opdrachtbeschrijving FROM form_entry"); // Query to fetch data from database table and storing in $results
if(!empty($results)) // Checking if $results have some values or not
{
echo "<table width='100%' border='0'>"; // Adding <table> and <tbody> tag outside foreach loop so that it wont create again and again
echo "<tbody>";
foreach($results as $row){
echo "<tr>"; // Adding rows of table inside foreach loop
echo "<th>ID</th>" . "<td>" . $row->id . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>Voornaam</th>" . "<td>" . $row->voornaam . "</td>"; //fetching data from user_ip field
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>Achternaam</th>" . "<td>" . $row->achternaam . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>Bedrijfsnaam</th>" . "<td>" . $row->bedrijfsnaam . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>Telefoonnummer</th>" . "<td>" . $row->telefoonnummer . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>E-mailadres</th>" . "<td>" . $row->emailadres . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>Titel opdracht</th>" . "<td>" . $row->titel_opdracht . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>Opdrachtbeschrijving</th>" . "<td>" . $row->opdrachtbeschrijving . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo '<td><a href="single_assignment_page.php?id='.$row->id.'">Hello</td>';
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
}
?>
single_assignment_page.php
<?php $assignment_id = $_GET['id']; ?>
<?php get_header(); ?>
<?php the_content(); ?>
<p>Hey</p>
<p>Hey</p>
<p>Hey</p>
<p>Hey</p>
<p>Hey</p>
<p>Hey</p>
<p>Hey</p>
<?php get_footer(); ?>
I already tried some things:
Tried to redirect without the id at the end of the url, then he still shows the index.php content.
Tried to redirect to a other PHP file, but it is still showing the content of index.php.
Edit the .htaccess file but I still got the same problem.
I hope someone can help me out, because I've been stuck with this problem for a whole day. Thanks for the effort.
Currently, I create a table that displays data from the database (JSON). In that table, I want to check is the data exists or not. Let's say if data is empty, I want to display "No booking data available at these moments".
The problem is, I don't know how to check the existing data. For now, if the data is empty, the table appears with <th> only and no words "No booking data available at these moments".
Below is my current code:
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = file_get_contents($url);
$json = json_decode($data);
if(empty($json)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
Try the following code:
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = #file_get_contents($url);
$json = json_decode($data);
if($json === FALSE && empty($json)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
I already solved my question. I just add "bookingList" at the empty json
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = file_get_contents($url);
$json = json_decode($data);
if(empty($json->bookingList)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
I am trying to create a CRUD dashboard, using a MySql backend and a bootstrap front-end with PHP and PDO to communicate with the database. I am a noob to web development, but not to coding.
The goal is to create a web app to log my patient consults. Thus, my table structure is a single "main" table and two children tables with relationships to the "main" table, named "consults" and "procedures".
I am trying to make a dashboard, where I display my "main" table, and then add two children tables below it. (Later on I will style it better, but I am trying to get this working).
The following is the best MWE I could think of (would love it if someone had a simpler solution). The first "logbook patients" table works well, and displays rows of patients well. Its the second table that is the problem, and in particular:
$sql = "SELECT * FROM proc";
if($result = $pdo->query($sql)){
if($result->rowCount() > 0){
This is the area I keep getting an error. The error is:
Fatal error: Uncaught Error: Call to a member function query() on null in /home/paincl5/public_html/logbook/logbook.php:110 Stack trace: #0 {main} thrown in /home/paincl5/public_html/logbook/logbook.php on line 110
The code at line 110 is
unset($pdo);
My full code is:
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header clearfix">
<h2 class="pull-left">Logbook Patients</h2>
<a href="create.php" class="btn btn-success pull-right" >Add New Patient</a>
</div>
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM main";
if($result = $pdo->query($sql)){
if($result->rowCount() > 0){
echo "<div style='height:300px;overflow-y:scroll;;'>";
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Surname</th>";
echo "<th>first_name</th>";
echo "<th>DOB</th>";
echo "<th>Hospital</th>";
echo "<th>MRN</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = $result->fetch()){
echo "<tr>";
echo "<td>" . $row['Surname'] . "</td>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['DOB'] . "</td>";
echo "<td>" . $row['Hospital'] . "</td>";
echo "<td>" . $row['MRN'] . "</td>";
echo "<td>";
echo "<a href='read.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='update.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</div>";
// Free result set
unset($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
}
// Close connection
unset($pdo);
?>
</div>
</div>
</div>
</div>
// Procedure Table
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header clearfix">
<h2 class="pull-left">Procedures</h2>
<a href="create_proc.php" class="btn btn-success pull-right" >Add New Procedure</a>
</div>
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM proc";
if($result = $pdo->query($sql)){
if($result->rowCount() > 0){
echo "<div style='height:300px;overflow-y:scroll;;'>";
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Procedure Type</th>";
echo "<th>Procedure Name</th>";
echo "<th>Notes</th>";
echo "<th>Action</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = $result->fetch()){
echo "<tr>";
echo "<td>" . $row['procedure_type'] . "</td>";
echo "<td>" . $row['procedure_name'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>";
echo "<a href='update.php?id=". $row['id1'] ."' title='Update Record' data-toggle='modal' data-target='#myModal' ><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='delete.php?id=". $row['id1'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</div>";
// Free result set
unset($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
}
// Close connection
unset($pdo); //Here occurs the error (line 110)
?>
</div>
</div>
</div>
</div>
You are destroying your $pdo variable with unset($pdo) so any subsequent calls are trying to run methods against a null object.
Try removing references to that unset.
I'm assuming that the $pdo object is coming from config.php. Since you're using require_once, it will only include the config file the first time the require_once is called. That's why the $pdo is destroyed and not recreated.
I'm creating a thumbnail with a title, image and caption on it. I'm trying to select data from my table to show it into my homepage. Can someone help me to create a normal thumbnail in my php that contains the detail from my sql. I tried to search and can't find how to create a thumbnail using php and not html.
$sql = "SELECT * FROM news";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>first_name</th>";
echo "<th>last_name</th>";
echo "<th>email</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['image'] . "</td>";
echo "<td>" . $row['caption'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
In short, is there a way to create a php file from this?
<div class="col-md-4">
<div class="thumbnail">
<img alt="Memory" img src="../../images/a2.jpg">
<div class="caption">
<h3><b>
Title
</b></h3>
<p>
Caption Caption Caption Caption Caption
</p>
<p align="right">
<a class="btn btn-primary" href="news2.html">Read More</a>
</p>
</div>
</div>
</div>
Do you want to replace your table structure with that template structure? You'll need to adjust some of the data to fill the hyperlink (I don't know how you want to build that).
while($row=mysqli_fetch_array($result)){
echo "<div class=\"col-md-4\">";
echo "<div class=\"thumbnail\">";
echo "<img alt=\"Memory\" src=\"../../images/{$row["image"]}\">";
echo "<div class=\"caption\">";
echo "<h3>{$row["title"]}</h3>";
echo "<p>{$row["caption"]}</p>";
echo "<p align=\"right\">";
echo "<a class=\"btn btn-primary\" href=\"news2.html\">Read More</a>";
echo "</p>";
echo "</div>";
echo "</div>";
echo "</div>";
}
So i got this for display in row my sql select:
$result = mysql_query("SELECT nome_sitio, horario, contato, morada, imagem FROM sitio where id_tipo=1");
echo "<table border='1'>
<tr>
<th>Nome</th>
<th>Horário</th>
<th>Contato</th>
<th>Morada</th>
<th>Imagem</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['nome_sitio'] . "</td>";
echo "<td>" . $row['horario'] . "</td>";
echo "<td>" . $row['contato'] . "</td>";
echo "<td>" . $row['morada'] . "</td>";
echo "<td>" . $row['imagem'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
But i made a design in html, that with html and css looks like this:
http://i.stack.imgur.com/gb1s9.png
And the html code is:
<div id="sitios">
<div class="imageRow">
<div class="single">
<img src="backoffice/images_sitios/thumbnails/$imagem"/>
</div>
</div>
<div id="texto">
<h2><b>$nome_sitio</b></h2>
<h3><b>Morada:</b></h3> $morada</br>
<h3><b>Horário:</b></h3> $horario</br>
<h3><b>Contato:</b></h3> $contato</br>
<h3><b>Freguesia:</b></h3> $idfreguesia
</div>
</div>
Can someone help me replacing the text with the vars?
You need to escape back to PHP to display the variables:
<div id="sitios">
<div class="imageRow">
<div class="single">
<img src="backoffice/images_sitios/thumbnails/<?php echo $imagem; ?>"/>
</div>
</div>
<div id="texto">
<h2><b><?php echo $nome_sitio; ?></b></h2>
<h3><b>Morada:</b></h3> <?php echo $morada; ?></br>
<h3><b>Horário:</b></h3> <?php echo $horario; ?></br>
<h3><b>Contato:</b></h3> <?php echo $contato; ?></br>
<h3><b>Freguesia:</b></h3> <?php echo $idfreguesia; ?>
</div>
</div>