Can anybody help me why my code is not fetching Marahti database values in PDF.
Here is my Code:
<?php
GLOBAL $html;
mb_internal_encoding("UTF-8"); header('Content-Type: text/html; charset=utf-8');
ini_set('display_errors', true);
$con=mysql_connect('localhost','root') or die('Error');
mysql_select_db('DemoMarathi');
$result = mysql_query("SET NAMES utf8")or die('error'.mysql_error());
$cmd = "select * from Demo_hindi";
$result = mysql_query($cmd);
while($row = mysql_fetch_assoc($result))
{
$html .= '<td>'.$row['DemoMarathi'].'</td><td>' . $row['DemoValues']. '</td>';
$pdf->Text(105, 73,"hi".$myrow['DemoMarathi']);
$pdf->Text(105, 73,"hi".$myrow['DemoValues']);
$pdf->Write(75,"".$myrow['DemoMarathi']);
$pdf->Write(90,"".$myrow['DemoValues']);
}
include('MPDF FULL_PACKAGE/mpdf60/mpdf.php');
$mpdf=new mPDF();
$mpdf->WriteHTML($html.$myrow['DemoMarathi']);
$mpdf->WriteHTML($html.$myrow['DemoValues']);
$mpdf->Output();
exit;
?>
PDF OUTPUT FILE
Related
I have this export button that needs to xport data fro my database to an excel(csv) file but when i press itthe complete html is shown in the csv file.
here is my ode for the export:
if (isset($_POST["export"])) {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('example','example','example','example','example','example','example','example','example','example'));
$query = "SELECT example,example,example,example,example,example,example,example,example,example FROM user";
$stmt = $con->prepare($query);
$stmt->execute();
fclose($output);
exit();
}
Edit:
This is my complete file with the code in it, i tried both options that were given below and they didn't seem to work. It still prints the complete html into a csv file.
<?php
if (isset($_POST["export"])) {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('example','example','example','example','example','example','example','example','example','example'));
$query = "SELECT example,example,example,example,example,example,example,example,example,example FROM user";
$stmt = $con->prepare($query);
$stmt->execute();
fclose($output);
exit();
}
print '<div class="dropdown">
<button class="dropbtn">Kies een Lijst... <i class="fa fa-caret-down"></i> </button>
<div class="dropdown-content">
Gehele Lijst
Namen/Social/Soort
Namen & Soort
Soort
Namen & Categorie Bordspellen
Namen & Categorie Bordspellen
Namen
</div>
</div> ';
function getKeys($con, $query)
{
$result = $con->query($query);
$row = $result->fetch(PDO::FETCH_ASSOC);
return array_keys($row);
}
function getValues($con, $query)
{
$data = $con->query($query);
$data->setFetchMode(PDO::FETCH_ASSOC);
return $data;
}
$query = "SELECT example,example,example,example,example,example,example,example,example,example FROM user";
//Tabel 1
print "<table id='een'>";
$array_keys = getKeys($con, $query);
print " <tr>";
foreach ($array_keys as $value) {
print " <th>$value</th>";
}
print " </tr> ";
//Values
$data = getValues($con, $query);
foreach ($data as $row) {
print " <tr> ";
foreach ($row as $name => $value) {
print " <td>$value</td> ";
}
print " </tr> ";
}
print '<form method="post" action="index.php?pages=export1"><button type="submit" name="export" value="export" style="width: 5%; height: 5%">Export</button></form>';
//export to csv
print "</table> ";
print '
<footer class="w3-center footer" style="margin-top: 25%">
<div class="w3-xlarge w3-section">
<?php $_SESSION["loggedin"] = true;
if ($_SESSION["loggedin"] === true) {
?>
<h6><br>© Big Bang 2020 Uitloggen</h6>
<?php
}
?>
</div>
</footer>';
Edit 2
maybe it helps that i show the result in the csv file.
csv file:
The header is a header.php file which is included in the index.php file automatically.
If you have other PHP and HTML in your script located earlier than the code shown, then that content will still be output by PHP - everything in the script will be output unless you specifically instruct it not to be. And you've decided to redirect all that output to a file download, so the result is inevitable - all the output goes into the file.
You need to make sure that other content doesn't get output when the user has chosen the export option. This is simple enough:
Either:
Just put the if (isset($_POST["export"])) {
as the first line of the script so that nothing else is output first. The script will already end after that due to your exit() command, so no other output would then be included in the download. (If you also have a header file which outputs HTML included before this, then this option won't be sufficient, you'll need to use the second option below - which is arguably a better separation of concerns anyway.)
OR
put the export code into a separate PHP script which doesn't have any other purpose or function, then there is no danger of other content being accidentally included in the file. Whatever form you are using to request the export should be changed to post back to that script instead.
<title>Orders Export</title>
<body>
<?php
header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename=download.xls');
$con = mysqli_connect('localhost','suresafe_admin','iwant$100','suresafe_suresafety');
$query = "select * from `orders_approval` where `approve`='1' and `company_name`='GAVL-F111'";
$result = mysqli_query($con,$query);
$output = '';
if(mysqli_num_rows($result) > 0)
{
$output .= '?>
<table class="table" bordered="1">
<tr>
<th>order_no</th>
<th>order_date</th>
<th>order_name</th>
<th>total_amount</th>
</tr><?php
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["order_no"].'</td>
<td>'.$row["order_date"].'</td>
<td>'.$row["order_name"].'</td>
<td>'.$row["total_amount"].'</td>
</tr>
';
}
$output .= '</table>';
}?>
</body>
</html>
The code is simple. Working well in local. But when I use this in my website on server. It shows only table with data. It don't export that data in Excel.
order_no order_date order_name total_amount
100000705 2017-05-07 MR. PRADEEP Y 113500
100000708 2017-05-11 MR. A SRINIVASA RAO 5448
100000725 2017-05-30 MR. A SRINIVASA RAO 77180
Here is the result I can see when I click on export link.
In local server, it is easily exported.
If you had configured your server properly, you would be seeing warnings. You cannot send a header after data has already been output. In addition, the data you're sending is not application/xls (which is not a valid MIME type) it's text/html. You're also outputting "?>" and "<?php" into your HTML, which will not work too well.
However, I would suggest going with CSV for the data you're outputting:
<?php
$con = mysqli_connect("localhost", "suresafe_admin", "iwant$100", "suresafe_suresafety");
$query = "SELECT order_no, order_date, order_name, total_amount from orders_approval WHERE approve = 1 AND company_name = 'GAVL-F111'";
$result = mysqli_query($con, $query);
$output = "";
if(mysqli_num_rows($result) > 0) {
$output .= "order_no,order_date,order_name,total_amount\n";
while($row = mysqli_fetch_assoc($result)) {
$output .= "$row[order_no],$row[order_date],$row[order_name],$row[total_amount]\n";
}
}
header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=download.csv");
echo $output;
I'm working on this application that reads confidential documents stored in the Blob of my Oracle 11g Database. What I have implemented so far is a php page that queries for all available blobs in the table and prints href's like this:
<html>
<head>
</head>
<body>
<?php
$i = 1;
echo "Welcome User!</br>";
$conn = OCILogon("abc","abc","abc_server");
$qry = "select id from some_table order by ID";
$stmt = ociparse ($conn,$qry);
OCIDefineByName($stmt,"ID",$id);
OCIExecute($stmt);
while ( $row = OCI_Fetch_Array($stmt, OCI_ASSOC+OCI_RETURN_LOBS) ) {
print "<a href = 'readMe.php?id=$id' target='_blank'>Document $i</a></br>";
$i = $i+1;
}
?>
</body>
</html>
readMe.php
<?php
session_start();
$id = $_GET[id];
$conn = OCILogon("abc","abc","abc_server");
$qry = "select doc_file,doc_name from some_table where ID =".$id;
//echo $qry;
$stmt = ociparse ($conn,$qry);
OCIDefineByName($stmt,"DOC_FILE",$blobFile);
OCIDefineByName($stmt,"DOC_NAME",$blobFileName);
OCIExecute($stmt);
while ($row = OCI_Fetch_Array($stmt, OCI_ASSOC+OCI_RETURN_LOBS))
{
$a = $row['DOC_FILE'];
}
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $blobFileName . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
print $a;
?>
The problem is that it produces this URL:
http://999.999.999.888/Some_work/ReadBlob/readMe.php?id=47
That is, the ID of every document in the browser. How can I avoid this? I tried using $_POST but it didn't open the document. ANy help would be highly appreciated.
I am trying to create an XML file output in PHP for a remote phone book on an IP Phone, here is the code i have:
<?php
$conn=mysql_connect("localhost","user","********");
mysql_select_db("db_name",$conn);
header("Content-Type: text/xml");
header("Connection: close");
header("Expires: -1");
?>
<YealinkIPPhoneDirectory>
<?php
$output='<YealinkIPPhoneDirectory>\n';
$sql="SELECT * from contacts ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs)) {
$output .= "<DirectoryEntry>\n";
$output .= "<Name>Mobile:</Name>\n";
$output .= "<Telephone>" . $result["mobile"] . "</Telephone>\n";
$output .= "</DirectoryEntry>\n";
}
$output='</YealinkIPPhoneDirectory>\n';
echo '$output';
?>
but i get this error message:
This page contains the following errors:
error on line 3 at column 8: Extra content at the end of the document
Below is a rendering of the page up to the first error.
$output
<?php
$conn=mysql_connect("localhost","user","********");
mysql_select_db("db_name",$conn);
header("Content-Type: text/xml");
header("Connection: close");
header("Expires: -1");
$output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$output .= '<YealinkIPPhoneDirectory>\n';
$sql="SELECT * from contacts ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs)) {
$output .= "<DirectoryEntry>\n";
$output .= "<Name>Mobile:</Name>\n";
$output .= "<Telephone>" . $result["mobile"] . "</Telephone>\n";
$output .= "</DirectoryEntry>\n";
}
$output.='</YealinkIPPhoneDirectory>';
echo $output;
?>
You need to remove this line:
echo '$output';
and replace it with this:
echo $output;
Here is a sample:
https://eval.in/96740
Note how singlequoted values are literally echoed, so you literally see $output as your output.
thank's for help. I have problem displaying images retrieving from my database.
I cant see the image when loading image.php in img src or directly from the page. When i display the variable without header('Content-type: image/jpeg'); i can see all the code inside, as i put this line all goes off.
I have a table called TABLE with id, title, img stored as longblob directly uploaded inside phpmyadmin.
Can anyone help me?
index.php
<?php
session_start();
include "admin/include/connection2.php";
$data = new MysqlClass();
$data->connect();
$query_img ="SELECT * FROM table ORDER BY data ASC LIMIT 4";
$post_sql = $data->query($query_img);
if(mysql_num_rows($post_sql) > 0){
while($post_obj = $data->estrai($post_sql)){
$id = $post_obj->id;
$titolo = stripslashes($post_obj->title);
$data_articolo = $post_obj->data;
$immagine = $post_obj->img;
// visualizzazione dei dati
echo "<h2>".$titolo."</h2>";
echo "Autore <b>". $autore . "</b>";
echo "<br />";
echo '<'.'img src="image.php?id='.$post_sql['id'].'">';
echo $id;
echo "<hr>";
}
}else{
echo "no post aviable.";
}
// here is the image.php code
<?php
include "admin/include/connection2.php";
$data = new MysqlClass();
// connect
$data->connetti();
$id = $_GET['id'];
echo $id;
$query = mysql_query("SELECT * FROM articoli_news WHERE id='".$id."'"; //even tried to send id='1' but not working
echo $query;
$row = mysql_fetch_array($query);
echo $row['id']; //correct displaying
$content = base64_decode($query['img']);
header('Content-type: image/jpeg');
echo $content;
?>
Delete all "echo" commands except "echo $content;" because there are also appear in the output, and damage your image.
And use ob_start(); in the begining of the script, and check out your script file not contain any of whitespace characters before or after the php begint and close tags .