未加星标

PHP Save as PDF does not work

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二05 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

Good Day!

I have a dropdown menu which select employee number and shows table data on basis of that particular selection. I have save as pdf code which saves table data in pdf. It is working fine but my table column headers are only shown not the values.

I have dropdown in one file having javascript which is sent to another file where my table is shown.

Below is the code for my all files and what I have tried for this so far.

For Dropdown: <php include("connect-db.php"); ?> <html> <head> <title>PHP insertion</title> <link rel="stylesheet" href="css/insert.css" /> <link rel="stylesheet" href="css/navcss.css" /> <script> function showUser(str) { if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("txtHint").innerHTML = xmlhttp.responseText; } }; xmlhttp.open("GET","search_empnumber.php?emp_id="+str,true); xmlhttp.send(); } } /*function showAssessories(acc) { if (acc == "") { document.getElementById("txtHint2").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("txtHint2").innerHTML = xmlhttp.responseText; } }; xmlhttp.open("GET","getassessories.php?emp_id="+acc,true); xmlhttp.send(); } }*/ </script> </head> <body> <div class="maindiv"> <?php include("includes/head.php");?> <?php include("menu.php");?> <div class="form_div"> <form> <div class="forscreen"> <h1>Search Records:</h1> <p>You may search by Employee Number</p> <select name="employeenumber" class="input" onchange="showUser(this.value)"> <option value="">Please Select Employee Number:</option> </div> <?php $select_emp="SELECT distinct(emp_number) FROM employees"; $run_emp=mysql_query($select_emp); while($row=mysql_fetch_array($run_emp)){ $emp_id=$row['emp_id']; $first_name=$row['first_name']; $last_name=$row['last_name']; $emp_number=$row['emp_number']; $total_printers=$row['total_printers']; $total_scanners=$row['total_scanners']; $total_pc=$row['total_pc']; $total_phones=$row['total_phones']; $other_equips=$row['other_equips']; ?> <option value="<?php echo $emp_number;?>"><?php echo $emp_number;?></option> <?php } ?> </select> <html> </form> </div> <br> <div id="txtHint"></div> <br> <div id="txtHint2"></div> </div> <?php include 'includes/foot.php';?> </body> </html> The function for dropdown: onchange="showUser(this.value)" function showUser(str) { if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("txtHint").innerHTML = xmlhttp.responseText; } }; xmlhttp.open("GET","search_empnumber.php?emp_id="+str,true); xmlhttp.send(); } } search_empnumber.php File: <!DOCTYPE html> <html> <form action="search_empnumber.php" method="POST"> <input type="submit" value="SAVE AS PDF" class="btnPDF" name="submit" /> </form> <head> <style> table { width: 100%; border-collapse: collapse; } table, td, th { border: 1px solid black; padding: 5px; } th {text-align: left;} .link{ color:#00F; cursor:pointer;} </style> </head> <body> <?php //$emp_id =($_REQUEST['emp_id']); $emp_id =($_REQUEST['emp_id']); $count=1; include("connect-db.php"); //$sql = "SELECT * from employees where department='".$department."'"; //$sql = "select * from employees as pg inner join accessories as pd on pg.emp_number= pd.emp_number "; //$result = mysql_query($sql) or die(mysql_error()); //$result = mysql_query($query) or die(mysql_error()); //$emp_id =($_POST['employeenumber']); $sql="SELECT * FROM employees WHERE emp_number = '".$emp_id."'"; $result = mysql_query($sql) or die(mysql_error()); $count=1; echo "<table> <tr> <th>S.No</th> <th>First Name</th> <th>Last Name</th> <th>Employee Number</th> <th>Department</th> <th>Email</th> <th>Total Printers</th> <th>Total Scanners</th> <th>Total Pc</th> <th>Total Phones</th> <th>Other Equipments</th> </tr>"; while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td>" . $count . "</td>"; echo "<td>" . $row['first_name'] . "</td>"; echo "<td>" . $row['last_name'] . "</td>"; echo "<td>" . $row['emp_number'] . "</td>"; echo "<td>" . $row['department'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['total_printers'] . "</td>"; echo "<td>" . $row['total_scanners'] . "</td>"; echo "<td>" . $row['total_pc'] . "</td>"; echo "<td>" . $row['total_phones'] . "</td>"; echo "<td>" . $row['other_equips'] . "</td>"; echo "</tr>"; $count++; } echo "</table>"; echo '<div class="forscreen">'; // echo '<br />';echo '<button class="btnPrint" type="submit" value="Submit" onclick="window.print()">Print</button>'; //echo '<input type="submit" value="SAVE AS PDF" class="btnPDFsearch" name="submit"/>'; // echo '<input type="submit" value="SAVE AS PDF" class="btnPDF" name="submit" />'; echo '</div>'; echo '<div class="forscreen">'; //echo '<br />';echo '<button class="btnPrevious" type="submit" value="Submit" onclick="history.back(); return false;">Previous Page</button>'; echo '</div>'; ?> </body> </html> PDF code (I tried) in same file of search_empnumber: <?php error_reporting(E_ALL ^ E_DEPRECATED); include('connect-db.php'); ?> <?php //if($_POST['submit']){ if (isset($_POST['submit'])){ require_once 'includes/practice.php'; $pdf->SetFont('times', '', 11); $tb1 = '</br></br> <table cellspacing="0" cellpadding="5" border="1"> <tr style="background-color:#f7f7f7;color:#333; "> <td width="60">First Name</td> <td width="60">Last Name</td> <td width="80">Employee Number</td> <td width="80">Department</td> <td width="60">Email</td> <td width="80">Total Printers</td> <td width="80">Total Scanners</td> <td width="60">Total PCs</td> <td width="60">Total Phones</td> <td width="60">Other Equipments</td> </tr> </table>'; include('connect-db.php'); //$emp_id =($_POST['emp_id']); $emp_id =($_POST['employeenumber']); $result1= mysql_query("SELECT * FROM employees where emp_number = '".$emp_id."'"); while($row = mysql_fetch_assoc($result1)){ $tb2 = '<table cellspacing="0" cellpadding="5" border="1"> <tr> <td width="60">' . $row['first_name'] . '</td> <td width="60">' . $row['last_name'] . '</td> <td width="80">'. $row['emp_number'] .'</td> <td width="80">'.$row['department'].'</td> <td width="60">'.$row['email'].'</td> <td width="80">'.$row['total_printers'].'</td> <td width="80">'.$row['total_scanners'].'</td> <td width="60">'.$row['total_pc'].'</td> <td width="60">'.$row['total_phones'].'</td> <td width="60">'.$row['other_equips'].'</td> </tr> </table>'; $tb1 = $tb1.$tb2; } $pdf->writeHTML($tb1, true, false, false, false, ''); ob_end_clean(); $pdf->Output('Report.pdf', 'D'); } ?>

The files i.e. practoce.php and pdf libraries are not added becuase they are just creating tables in defined formats

You are mixing up GET and POST . Try one (or both) of the following:

1) In the dropdown code, replace <form> with:

<form method="POST">

2) In the table generation code, read the value back with:

$emp_id =($_REQUEST['employeenumber']);

and also:

if (isset($_REQUEST['submit'])){ To add to your problems, in the first version of search_empnumber.php you posted, you read back $emp_id =($_REQUEST['emp_id']); when the posted value will actually be in $_REQUEST['employeenumber'] .

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

代码区博客精选文章
分页:12
转载请注明
本文标题:PHP Save as PDF does not work
本站链接:https://www.codesec.net/view/611187.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(93)