I am getting this error:
Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in /home/emscompl/public_html/pdf_email/dompdf/include/table_frame_decorator.cls.php on line 304 and defined in /home/emscompl/public_html/pdf_email/dompdf/include/frame.cls.php on line 726
Here is the dompdf code.
<?php
/*$dir = dirname(__FILE__);
require_once($dir.'/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->load_html_file("http://ems-complete.com/pdf_email/patient-report.php");
$dompdf->render();
$dompdf->stream("file.pdf");*/
$course = $_REQUEST['course'];
$dir = dirname(__FILE__);
require_once($dir.'/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->load_html(file_get_contents("http://ems-complete.com/courseroster/courseroster.php?course=".$course));
$dompdf->render();
// $dompdf->set_paper(2412, 3222);
$dompdf->stream("courseroster.pdf");
// exit(0);
?>
Here is the PHP HTML
<html>
<head>
<link type="text/css" media="screen" rel="stylesheet" href="stylesheets/courseroster.css" />
<link type="text/css" media="print" rel="stylesheet" href="stylesheets/print.css" />
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
function PrintDivData(crtlid)
{
var ctrlcontent = document.getElementById(crtlid);
var printscreen = window.open('','','left=1,top=1,width=1,height=1,toolbar=0,scrollbars=0,status=0');
printscreen.document.write(ctrlcontent.innerHTML);
printscreen.document.close();
printscreen.focus();
printscreen.print();
printscreen.close();
}
</script>
<input type="button" name="Print" value="Print" onClick="javascript:PrintDivData('container');" Runat="Server" />
<?php
$course = $_REQUEST['course'];?>
<?php
$connect = mysql_connect('localhost','db','pass') or die(mysql_error());
$selectdb = mysql_select_db('emscompl_joom1283',$connect);
?>
<?php
$qry = "SELECT * FROM courses
WHERE id = $course";
$result = mysql_query($qry);
$row = mysql_fetch_array($result);
$qry2 = "SELECT s.fullname, cs.* FROM registered_users AS `s`
LEFT OUTER JOIN course_students AS cs ON s.userid = cs.userid
WHERE cs.courseid = $course
ORDER BY s.fullname";
$result2 = mysql_query($qry2);
echo "<a href=http://www.ems-complete.com/pdf_email/form_courseroster.php?course=".
$course.">Display PDF</a>";?>
<div class="container" id ="container">
<div class="header"><?php echo $row['coursename'];?> Roster</div>
<div class="coursestatus"><p>Course Status</p>
<p><?php echo $row['status'];?></p>
</div>
<div class="startdate"><p>Start Date</p>
<p><?php echo $row['startdate'];?></p>
</div>
<div class="enddate"><p>End Date</p>
<p><?php echo $row['enddate'];?></p>
</div>
<div class="dayofweek"><p>Class Held on:</p>
<p><?php echo $row['dayofweek'];?></p>
</div>
<div class="leadinstructor"><p>Lead Instructor</p>
<p><?php echo $row['leadinstructor'];?></p>
</div>
<div class="assistantinstructor"><p>Assistant Instructors</p></div>
<div class="enrolledstudents">
<p>Enrolled Sutdents</p>
<table width="760" border="0">
<tr>
<th width="223">Student Name</th>
<th width="102">Phone</th>
<th width="90">Email</th>
<th width="100">Status</th>
<th width="220">Document Report</th>
</tr>
<tr>
<?php while ($row2 = mysql_fetch_array($result2)) { ?>
<td><?php echo $row2['fullname'];?></td>
<td><?php echo $row2[''];?></td>
<td><?php echo $row2[''];?></td>
<td><?php if ($row2['studentstatus']== 0 ){
echo "Interested";
}
else if ($row2['studentstatus']== 1 ){
echo "Entrance Process";
}
else if ($row2['studentstatus']== 2 ){
echo "Incomplete Entrance Process";
}
else if ($row2['studentstatus']== 3 ){
echo "Enrolled";
}
else if ($row2['studentstatus']== 4 ){
echo "Course Completed";
}
else if ($row2['studentstatus']== 5 ){
echo "NREMT Skills Complete";
}
else if ($row2['studentstatus']== 6 ){
echo "NREMT Cognitive Complete";
}
else if ($row2['studentstatus']== 7 ){
echo "State Certified";
}?></td>
<td><?php echo "Document Report"
;?>
</td>
</tr>
<?php } ?>
</table>
<p> </p>
</div>
<div class="footer">
<p> </p>
</div>
</div>
</body>
</html>
In your HTML-generating script you have an opening TR outside the while loop that looks like it should be inside the loop (the closing tag is inside the loop). This will cause an invalid document structure, and apparently one which dompdf is unable to parse.
FYI, the first thing to do if dompdf won't parse a document is to run it through a validator.
Related
I'm setting up a new Website and i want to show the results of a searching MySQLi query in boxes.
My php code....
$query = mysqli_query($con,"SELECT * FROM `products`");
while($row = mysqli_fetch_array($query)) {
echo "<img src='/Images/".$row['product_image']."' height='200' width='200'>"
echo '<h6> Id:'.$row['product_id'].'</h6>';
echo '<h6> Name:'.$row['product_name'].'</h6>';
echo '<h6> Proce:'.$row['product_price'].'</h6>';
}
With that code the results of a searching query are presented like this
I'm trying using with many ways to achieve a presentation of the results like this way:
Any idea or advice? Thank you
Use css "float: left"
$query = mysqli_query($con,"SELECT * FROM `products`");
while($row = mysqli_fetch_array($query)) {
echo '<div style="float:left">';
echo "<img src='/Images/".$row['product_image']."' height='200' width='200'>";
echo '<h6> Id:'.$row['product_id'].'</h6>';
echo '<h6> Name:'.$row['product_name'].'</h6>';
echo '<h6> Proce:'.$row['product_price'].'</h6>';
echo '</div>';
}
you can use bootstrap to achieve this. For example, just add class="col lg-4" inside the div tag, and you will have 3 columns for each row.
Sample code:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<section class="content">
<div class="container">
<div class="row">
<?php
$get = mysqli_query($con, "SELECT * FROM `products` ORDER BY `product_name`");
while ($products = mysqli_fetch_assoc($get)) { ?>
<div class="col-lg-4">
<div class="thumbnail" align="center">
<img src="admin/images/products/<?php echo $products['photo']; ?>" style="width: 220px; height: 150px">
<div class="caption">
<h4>
<?php echo $products['product_name']; ?>
</h4>
<span>$<?php echo number_format($products['price']); ?></span>
<br />
<br />
Detail
<input type="button" name="wishlist" id="add_wishlist" value="+ " onclick="addWishlist('<?php echo $products[id]; ?>', '<?php echo $id_user; ?>')" class="btn btn-info">
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
Hello so I have a site setup to where users can submit projects and it adds it to a upload folder and the database for user download anyway I want to have it so once a user submits a new project it creates a URL like “sitename.com/projects.html?projectname” or something like that. My code is below.
P.S Everything on my site works just need to learn how to create the url.
projects.html: Mainly used to display the recent projects.
<?php include("includes/header.php"); ?>
<?php
include_once 'dbconnect.php';
// fetch files
$sql = "select filename, title, description from tbl_files LIMIT 4";
$result = mysqli_query($con, $sql);
?>
<div id="container">
<div class="wrapper">
<div id="content">
<h2>Recent Projects <button style="float: right;">New Project</button></h2>
<p><table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>File Name</th>
<th>Description</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while($row = mysqli_fetch_array($result)) { ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><a href="uploads/<?php echo $row['filename']; ?>" download>Download</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</p>
<div id="column">
<div class="holder">
<h2>Welcome!</h2>
<ul id="latestnews">
<li class="last"> <p><?php
session_start();
include_once "vendor/autoload.php";
$page = new membership\Page(1);
if ($page->isValid() == true){
echo "Hello " . $_SESSION["username"] . "!<br /><br />
<a href='logout.html'>Logout</a>\n";
} elseif ($page->isValid() == false) { echo "<center>Please <a href='login.php'>Log in</a> to share projects.<br /> <a href='register.php'>Need A Account?</a></center>";}
?><br />
</p>
<br /></p>
</li>
</ul>
</div>
</div>
<br class="clear" />
</div>
</div>
<?php
error_reporting(E_ALL & ~E_NOTICE);
include('includes/memberlistconfig.php');
// call this file only after database connection
require_once 'functions.php';
?>
<div id="container">
<div class="wrapper">
<div id="content">
<h2>Categories</h2>
<p>
<div class="height20"></div>
<?php echo $emsg; ?>
<article>
Click on one of the categories to see what’s inside.
<ul>
<?php
$res = fetchCategoryTreeList();
foreach ($res as $r) {
echo $r;
}
?>
</ul>
</article>
</div></p>
<br class="clear" />
</div>
</div>
<?php include("includes/footer.php"); ?>
new-project.html: Allows used to upload a new project.
<?php
include_once('includes/header.php'); ?>
<?php
include_once 'dbconnect.php';
// fetch files
$sql = "select filename from tbl_files";
$result = mysqli_query($con, $sql);
?>
<?php
session_start();
include_once "vendor/autoload.php";
$page = new membership\Page(1);
if ($page->isValid() == true) {
?>
<div id="container">
<div class="wrapper">
<div id="content">
<h2>New Project</h2>
<p><center>
<form action='upload.php' method='post' enctype='multipart/form-data'>
<legend>Select File to Upload:</legend>
<div class='form-group'>
Title: <br /><input type='text' name='title' maxlength="255"/><br /><br />
Description: <br /><textarea type='text' name='description' maxlength="2000"></textarea><br /><br />
<input type='file' name='file1' />
</div>
<div class='form-group'><br />
<input type='submit' name='submit' value='Upload' class='btn btn-info'/>
</div>
<?php if (isset($_GET['st'])) { ?>
<div class='alert alert-danger text-center'>
<?php
if ($_GET['st'] == "success") {
echo "File Uploaded Successfully!";
} else {
echo 'Invalid File Extension!';
}
?>
</div>
<?php } ?>
</form></center>
</p><?php } ?>
<br /></div>
</p>
<div id="column">
<div class="holder">
<h2>Project Upload Rules</h2>
<ul id="latestnews">
This is this rules you must follow for uploading a project.<br /><br />
- You must own the project / script.<br />
- Must be 100% clean / safe.<br />
- Code must be easy to read.<br />
- No outdated code.<br />
<br />
If you don’t follow the rules your account who be banned.
<br />
</p>
<br /></p>
</li>
</ul>
</div>
</div>
<br class="clear" />
</div>
</div>
<?php include_once('includes/footer.php'); ?>
upload.php: This file uploads the info to the database.
<?php include('dbconnect.php'); ?>
<?php
//check if form is submitted
if (isset($_POST['submit']))
{
$filename = $_FILES['file1']['name'];
//upload file
if($filename != '')
{
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$allowed = ['zip', 'rar', 'php', 'html', 'sql'];
//check if file type is valid
if (in_array($ext, $allowed))
{
// get last record id
$sql = 'select max(id) as id from tbl_files';
$result = mysqli_query($con, $sql);
if (count($result) > 0)
{
$row = mysqli_fetch_array($result);
$filename = ($row['id']+1) . '-' . $filename;
}
else
$filename = '1' . '-' . $filename;
//set target directory
$path = 'uploads/';
$created = #date('Y-m-d H:i:s');
move_uploaded_file($_FILES['file1']['tmp_name'],($path . $filename));
$title = '';
if(!empty($_POST['title']))
{
$title = mysqli_real_escape_string($con, $_POST['title']);
}
$description = '';
if(!empty($_POST['description']))
{
$description = mysqli_real_escape_string($con, $_POST['description']);
}
// insert file details into database
$sql = "INSERT INTO tbl_files(filename, created, title, description) VALUES('$filename', '$created', '$title', '$description')";
mysqli_query($con, $sql);
header("Location: new-project.html?st=success");
}
else
{
header("Location: new-project.html?st=error");
}
}
else
header("Location: new-project.html");
}
?>
I am trying to make a shopping cart with php. I wanted to send id to a php code below in the file. I tried to do it with php_self. And I get these errors.
*Undefined index: movie_id in C:\xampp\htdocs\ITA_WEBSITE\shopping_cart.php on line 60
*mysqli_fetch_object() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\ITA_WEBSITE\shopping_cart.php on line 61
*Undefined index: cart in C:\xampp\htdocs\ITA_WEBSITE\shopping_cart.php on line 84
Here's the code
<?php
session_start();
include('dbconfig.php');
$result = mysqli_query($con,"SELECT * FROM movie_details");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Movie Store</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div class="container-fluid" id="maincontent">
<div class="row">
<?php while($product = mysqli_fetch_object($result)) { ?>
<div class="col-md-4 col-xs-12">
<div class="thumbnail customsthumbs">
<img src=<?php echo $product->image_path;?> alt=<?php echo $product->image_path;?>>
<div class="caption">
<h3 class="customh"><?php echo $product->movie_title;?></h3>
<p id="price">Price : $<?php echo $product->price;?></p>
<p style="text-align:center"><a href=<?php $_SERVER['PHP_SELF'].'?movie_id='?><?php echo $product->movie_id?> class="btn btn-primary custombtn" role="button">
<span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span>Add To Cart</a>
</p>
</div>
</div>
</div>
<?php } ?>
</div>
<?php
include('dbconfig.php');
include('movie_products.php');
$result = mysqli_query($con, 'SELECT * FROM movie_details WHERE movie_id = '.$_GET['movie_id']);
$product = mysqli_fetch_object($result);
if(isset($_GET['movie_id'])){
$item = new Item();
$item->movie_id = $product->movie_id;
$item->movie_title = $product->movie_title;
$item->price = $product->price;
$item->quantity = 1;
$_SESSION['shopping_cart'][] = $item;
}
?>
<div class="container-fluid">
<div class="row">
<div id="cart">
<h3 style="text-align: center;font-size: 40px;padding-top: 5px;">Cart</h3>
<div id="display_cart">
<table border="1" id="display_cart_table">
<tr>
<th>Movie Title</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php
$cart = unserialize(serialize($_SESSION['cart']));
for($i=0; $i<count($cart); $i++){
?>
<tr>
<td><?php echo $cart[$i]->movie_title;?></td>
<td><?php echo $cart[$i]->price;?></td>
<td></td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
movie_products.php file
<?php
class Item{
var $movie_id;
var $movie_title;
var $price;
var $quantity;
}
?>
Note: I tried to do this by following a tutorial
Need some help !!
Look at the following statement,
<p style="text-align:center"><a href=<?php $_SERVER['PHP_SELF'].'?movie_id='?> ...
^ see here
You forgot to use echo here. It should be,
<p style="text-align:center"><a href=<?php echo $_SERVER['PHP_SELF'].'?movie_id='?>...
Also, wrap your code block inside an if block, like this:
// your code
if(isset($_GET['movie_id'])){
include('dbconfig.php');
include('movie_products.php');
$result = mysqli_query($con, 'SELECT * FROM movie_details WHERE movie_id = '.$_GET['movie_id']);
$product = mysqli_fetch_object($result);
if(isset($_GET['movie_id'])){
$item = new Item();
$item->movie_id = $product->movie_id;
$item->movie_title = $product->movie_title;
$item->price = $product->price;
$item->quantity = 1;
$_SESSION['shopping_cart'][] = $item;
}
?>
<div class="container-fluid">
<div class="row">
<div id="cart">
<h3 style="text-align: center;font-size: 40px;padding-top: 5px;">Cart</h3>
<div id="display_cart">
<table border="1" id="display_cart_table">
<tr>
<th>Movie Title</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php
$cart = unserialize(serialize($_SESSION['cart']));
for($i=0; $i<count($cart); $i++){
?>
<tr>
<td><?php echo $cart[$i]->movie_title;?></td>
<td><?php echo $cart[$i]->price;?></td>
<td></td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
</div>
<?php
}
This is my php code
<?php
include_once 'conectDB.php';
$sql ='SELECT CHECKLISTS.USER_ID, CHECKLISTS.ADMIN_ID, PROGRAMS.PROGRAM_NAME
FROM CHECKLISTS
LEFT JOIN COMPUTERS
ON CHECKLISTS.USER_ID = COMPUTERS.COMPUTER_NAME
LEFT JOIN ADMINS
ON CHECKLISTS.ADMIN_ID = ADMINS.USER_ID
LEFT JOIN CHECKLIST_PROGRAMS
ON CHECKLISTS.ID = CHECKLIST_PROGRAMS.CHECKLIST_ID
LEFT JOIN PROGRAMS
ON PROGRAMS.ID = CHECKLIST_PROGRAMS.PROGRAM_ID
';
$result = $connection->query($sql);
$checklists = array();
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()) {
$checklists [] = $row;
}
} else {
echo '0 results';
}
$connection->close();
?>
And this is HTML CODE
in this foreach I don't know how to query and create table :(
<html>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<title>C.I.G. Check List</title></head>
<body>
<div class="container">
<div class="row" style="margin-top:10px;">
<div class="col-md-offset-2 col-md-8">
<div class="row" style="margin-top:20px;">
<div class="col-md-4"><h3>C.I.Gruop Checklist</h3></div>
<div class="col-md-6" style="margin-top:19px; font-size:20px;">New Item</div>
</div></div>
</div>
<div class="col-md-2"></div>
<div class="row" style="margin-top:20px;">
<div class="col-md-offset-1 col-md-9">
<!-- ส่วนแสดงผล -->
<?php
foreach ($checklists as $checklist) {
print_r($checklist);
}
?>
</div>
</div>
</div
</body>
</html>
You need to do like this:-
<table>
<?php
foreach ($checklists as $checklist) {
echo '<tr><td>'.$checklist.'</td></tr>';
}
?>
</table>
Creating table in foreach is simple. Try this:
<table>
<thead>
<tr>
<th>Check List</th>
</tr>
</thead>
<tbody>
<?php
foreach ($checklists as $checklist) {
?>
<tr>
<?php
echo "<td>" . $checklist . "</td>";
?>
</tr>
<?php
}
?>
</tbody>
</table>
One option can be:
<table>
<? foreach ($checklists as $checklist) { ?>
<tr>
<td>
<? echo $checklist; ?>
</td>
</tr>
<? } ?>
</table>
Within the loop, everything you write is repeated as many times as the checklist items
I've tried to run a php file on xampp which is installed in Ubuntu and WinXP. Both result in error, but it is success when tried to run on xampplite in WinXP. Any special configuration is need to be set on the full xampp version? The php code is as the following:
<?php
require_once('database.php');
// Get category ID
if(!isset($category_id)) {
$category_id = $_GET['category_id'];
if (!isset($category_id)) {
$category_id = 1;
}
}
// Get name for current category
$query = "SELECT * FROM categories
WHERE categoryID = $category_id";
$category = $db->query($query);
$category = $category->fetch();
$category_name = $category['categoryName'];
// Get all categories
$query = 'SELECT * FROM categories
ORDER BY categoryID';
$categories = $db->query($query);
// Get products for selected category
$query = "SELECT * FROM products
WHERE categoryID = $category_id
ORDER BY productID";
$products = $db->query($query);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- the head section -->
<head>
<title>My Guitar Shop</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
<!-- the body section -->
<body>
<div id="page">
<div id="header">
<h1>Product Manager</h1>
</div>
<div id="main">
<h1>Product List</h1>
<div id="sidebar">
<!-- display a list of categories -->
<h2>Categories</h2>
<ul class="nav">
<?php foreach ($categories as $category) : ?>
<li>
<a href="?category_id=<?php echo $category['categoryID']; ?>">
<?php echo $category['categoryName']; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div id="content">
<!-- display a table of products -->
<h2><?php echo $category_name; ?></h2>
<table>
<tr>
<th>Code</th>
<th>Name</th>
<th class="right">Price</th>
<th> </th>
</tr>
<?php foreach ($products as $product) : ?>
<tr>
<td><?php echo $product['productCode']; ?></td>
<td><?php echo $product['productName']; ?></td>
<td class="right"><?php echo $product['listPrice']; ?></td>
<td><form action="delete_product.php" method="post"
id="delete_product_form">
<input type="hidden" name="product_id"
value="<?php echo $product['productID']; ?>" />
<input type="hidden" name="category_id"
value="<?php echo $product['categoryID']; ?>" />
<input type="submit" value="Delete" />
</form></td>
</tr>
<?php endforeach; ?>
</table>
<p>Add Product</p>
</div>
</div>
<div id="footer">
<p>© <?php echo date("Y"); ?> My Guitar Shop, Inc.</p>
</div>
</div><!-- end page -->
</body>
</html>
The database has been created without any problem. Thanks