execute a php page in mpdf and make a pdf - php

mpdf seems to convert html page quite smoothly ..
but when i use php code which gets value from database then mdpf is outputting the php code in the pdf and not the executed results..
enter code here
<body>
<form >
<?php
include 'connection.php';
$query="select * from androidlogin";
$result=mysql_query($query);
while($i = mysql_fetch_array($result))
{
echo "<h3>". $i['user']. "&&" . $i['pass']. "</h3>";
}
?>
</form>
</body>
and the output to the pdf file is like
<?php include 'connection.php'; $query="select * from androidlogin";
$result=mysql_query($query);
while($i =mysql_fetch_array($result))
{
echo "". $i['user']. "&&" . $i['pass']. "";
}
?>
i want the php page to execute and then get converted to pdf , pls help ..

Please make changes in your php.ini file.Open dll extension in Your file this will solve your problem.

Related

How to include a seperate header file?

Hey so I am currently working on an html/php page.
I have a header file that I am supposed to include in my page but for some reason it's not working and I have no idea, I've done the same thing for all my other pages and it has worked so I don't know why all of a sudden its not working.
<?php
include 'header.php';
?>
<center>
<p>
This page utilizes several postgreSQL method calls. Such as pg_connect(),
pg_query(), and pg_fetch_result().
</p>
<!-- setup the table -->
<table border="1" width="75%">
<tr><th width="50%">Make</th><th width="15%">Model</th><th width="20%">Year</th><th width="15%">MSRP</th></tr>
<?php
$output = ""; //Set up a variable to store the output of the loop
//connect
$conn = pg_connect("host=127.0.0.1 dbname=slotegraafd_db user=slotegraafd password=100658347" );
//issue the query
$sql = "SELECT automobiles.make, automobiles.model, automobiles.year, automobiles.msrp
FROM automobiles
ORDER BY automobiles.year ASC";
$result = pg_query($conn, $sql);
$records = pg_num_rows($result);
//generate the table
for($i = 0; $i < $records; $i++){ //loop through all of the retrieved records and add to the output variable
$output .= "\n\t<tr>\n\t\t<td>".pg_fetch_result($result, $i, "Make")."</td>";
$output .= "\n\t\t<td>".pg_fetch_result($result, $i, "Model")."</td>";
$output .= "\n\t\t<td>".pg_fetch_result($result, $i, "Year")."</td>";
$output .= "\n\t\t<td>".pg_fetch_result($result, $i, "msrp")."</td>\n\t</tr>";
}
echo $output; //display the output
?>
</table>
<!-- end the table -->
</center>
</body>
</html>
This is my full set of code with the include statement. There is no opening html or body tag because it is in the header file therefore I am not supposed to add it in this page.
Anyway any help?
Thanks.
Make sure that the file path is correct. If this new file is in a folder, then you need to change your include statement.
For example, if this new file is in a folder called foo, you could say: include '/foo/header.php
Or you can use a relative path: include ../header.php
Read up on file paths if needed.
It should work just the way your code looks like. Maybe your path of header.php isnt correct, or the content can't be displayed / executed so it shows nothing.

Order of inclusion and interpretation for php and html

I am trying to display different content on a page based on some options.
Also, I am trying to avoid using php echo for all the html output.
I came up with the following solution accidentally, and now I'm confused about how it actually works.
test.php
<?php
function get_content() {
$page = 0;
if($page == 0)
include('page0.php');
else
include('page1.php');
}
?>
<html>
<body>
<?php echo get_content() ?>
</body>
</html>
page0.php
<?php
$link = "http://www.google.ca";
$name = "GOOGLE";
?>
<?= $name ?>
page1.php
<?php
$link = "http://www.yahoo.ca";
$name = "YAHOO";
?>
<?= $name ?>
It seems like the php interpreter would end up including html tags into a <?php ?> block when it reaches the following line, but somehow, this code works, and the outputted html is valid.
include('page0.php');
Can someone explain what exactly is going on here?
When a file is included, parsing drops out of PHP mode and into HTML
mode at the beginning of the target file, and resumes again at the
end. For this reason, any code inside the target file which should be
executed as PHP code must be enclosed within valid PHP start and end
tags.
From PHP manual, include function.

Retrieve image from database using CodeIgniter

this code work only in admin page but can't work in view page how to retrieve image from view page in codelgniter
code:
<?php
include('config.php');
$result = mysql_query("SELECT * FROM photos");
while($row = mysql_fetch_array($result))
{
echo '<div id="imagelist">';
echo '<p><img src="'.$row['location'].'"></p>';
echo '<p id="caption">'.$row['caption'].' </p>';
echo '</div>';
}
?>
Why you use mysql extension in codeigniter ?!
Even though the meaning of that code work in admin is you store your image inside admin folder
So for best practice
Please use codeIgniter as a FrameWork not a place to paste your procedural PHP code !
Also show us what is in $row['location'] ?!

Can't show the output in html

I have a function wich prints a number of credits:
<?php
function selectCredits()
{
include 'sqlvars.php';
$con = mysql_connect("localhost","bbbb","bbbb");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bbbb", $con);
$result = mysql_query($selectCredits);
while($row = mysql_fetch_array($result)){
echo $row['credits'];
}
}
?>
When I'm calling it from a php file by using:
<?php
include 'sql.php';
selectCredits();
?>
I can see the output, but when I'm inside of a HTML document I can't get the result using this code:
<center><b>Your credits: </b></center> <?php include 'sql.php'; selectCredits(); ?>
The output is always: Your credits: without the query result.
For sure I'm missing somthing really small. I'm not a php guy, but I'm willing to learn it, already lost an hour without any success.
If you really want html files to execute php code, try to add this line to htaccess:
AddType application/x-httpd-php .html
check your query statement '$selectCredits'. check table name and attribute name-'credits'. The $row['credits'] is not getting its value.
You have a problem in your code. You have written
while($row = mysql_fetch_array($result)){
echo $row['credits'];
}
You have used mysql_fetch_array and you have echoed $row with attribute value directly. If you are using mysql_fetch_array, then use $row[0], $row[1] or $row[2] etc. All the attributes come as an array. Thats why you should treat it as array index value. So, if "credit" attribute is at the 5th column in your database, then you should echo it as
echo $row['4'];
If you use mysql_fetch_assoc() instead of mysql_fetch_array, then you can write the attribute name directly.
E.g. then you can write
echo $row['credits'];
I hope, this will solve the issue. Please ask me if you have any further questions.
You should use a JavaScript tag to implement the PHP file like this:
<script type="text/javascript" src="credits.php"></script>
credits.php would have to output:
echo "document.write('" . $row['credits'] . "');";
Simple :)

How can I retrieve HTML/PHP code stored in a mySQL table and not have the PHP commented out?

I am storing in a mySQL table the HTML/PHP content of individual slides to be displayed on a single page.
Here is an example of HTML/PHP code stored in the mySQL table:
<p>Welcome <?php echo $userData['fname']; ?>!</p>
<p>You made it to the first slide!</p>
I retrieve the content of the slides in PHP with the following code:
<?php
$fetchedPageSlideData = mysql_query("SELECT * FROM pageSlides WHERE pageID = $pageID ORDER BY 'order' DESC") or die(mysql_error());
while ($pageSlideData = mysql_fetch_array($fetchedPageSlideData)) {
$pageSlideContent = $pageSlideData['content']; ?>
<div><?php echo $pageSlideContent; ?></div>
<?php }
?>
All of the HTML of the content displays correctly, but the PHP is inserted as follows:
<!--?php echo $userData['fname']; ?-->
So the PHP is commented out and doesn't display.
How can I retrieve the HTML/PHP code and have the PHP not commented out?
It might be a better idea to use placeholder strings in the DB data. Executing arbitrary php code from a DB can be dangerous. PHP is Evil
Look into PHP function eval(): http://php.net/manual/en/function.eval.php
Dropping in and out of the PHP interpreter makes your code rather difficult to read. Consider:
<?php
$f = mysql_query(
"SELECT *
FROM pageSlides
WHERE pageID = $pageID
ORDER BY 'order' DESC"
) or die(mysql_error());
while ($d = mysql_fetch_array($f)) {
print "<div>" . $d['content'] . "</div>\n";
}
Regardless there is no implicit nor explicit mechanism here which would inject the comment tags you've presented. However it may be the browser trying to make sense of the unescaped html code and <?php ... ?> tags.
Try:
print "<div>" . htmlentities($d['content']) . "</div>\n";
As a side note, you might consider using
print "<div>" . highlight_string($d['content']) . "</div>\n";
Or do you mean that you actually want to run the code stored in the database - if so, you're asking for a world of pain. Eval is not evil - but you really must know what you're doing to avoid getting bitten by it.

Categories