准备好的语句执行致命错误,变量与数据库表未命中匹配

编程入门 行业动态 更新时间:2024-10-11 05:23:16
本文介绍了准备好的语句执行致命错误,变量与数据库表未命中匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我得到以下错误致命错误:在第237行的/home/wt/public_html/view-reports.php中的非对象上调用成员函数execute().

I get the following error Fatal error: Call to a member function execute() on a non-object in /home/wt/public_html/view-reports.php on line 237 .

我也看到了另一个问题.生成的变量不会回显正确的相应数据.例如,$ rep_type回显位置.你能帮我这个忙吗?谢谢!测试网站网址在这里. ethioserver/~wt/view-reports.php?rep_id=144这个问题在wampserver中不可见.两台服务器上的php版本均为5.4.

I also see another problem. The variables generated doesn't echo the right corresponding data. For instance, $rep_type echo position. Could you please help me on this. Thank you! Test site url is here. ethioserver/~wt/view-reports.php?rep_id=144 The problem is not visible in wampserver. The php version in both servers is 5.4.

主要代码如下.

<?php //generate page $_GET['rep_id']>0; if ($_GET['rep_id']!=0){ require ('includes/db.php'); mysqli_select_db($con, $db_name); $sql= 'SELECT * FROM Reports'; $stmt = $con->prepare($sql); $stmt->execute(); $stmt->bind_result($rep_id, $rep_date, $rep_ledit_date, $rep_by, $rep_type, $department, $position, $report, $rep_to); $stmt->fetch(); //allow users to edit if($fname . ' '. $lname!=$rep_by){ echo '<div class="links"></div>'; } else { echo '<div class="links">'; echo '<a href="edit-this-report.php?rep_id=' . $rep_id; echo 'target="_blank" img src="images/pdf.png" alt="edit report" target="_blank" ><img src="images/edit.png"> </a>'; echo '</div>'; } echo '<div class="links"><a href="pdf/'. (str_replace(' ', '-',($rep_by) .'-'. str_replace(':','.',$rep_date))). '.pdf" target="_blank" img src="images/pdf.png" alt="download report"><img src="images/pdf.png"> </a></div>'; //start html creation ob_start(); echo "<h1>$rep_by ($rep_date)</h1>"; echo '<div class="infobar"><strong>Report Type: </strong>'. $position . '</div>' ; echo '<div class="infobar"><strong>Department: </strong>'. $rep_type . '</div>'; echo '<div class="infobar"><strong>Position: </strong>'. $department . '</div>'; echo $report; file_put_contents(('scripts/dompdf/html/'. (str_replace(' ', '-',($rep_by) .'-'. str_replace(':','.',$rep_date))). '.html'), ob_get_contents()); if ($rep_ledit_date>0) {echo '<div class="infobar">' . 'Last Edited: ' . $rep_ledit_date . '</div>'; } else {echo ""; //end html creation ob_end_flush();} //generate pdf using dompdf require_once "scripts/dompdf/dompdf_config.inc.php"; $file='scripts/dompdf/html/'. (str_replace(' ', '-',($rep_by) .'-'. str_replace(':','.',$rep_date))) . '.html'; $dompdf = new DOMPDF(); $dompdf->load_html_file($file); $dompdf->render(); $canvas = $dompdf->get_canvas(); //For the header $header = $canvas->open_object(); $font = Font_Metrics::get_font("helvetica", "bold"); $date = date("Y-m-d H:i:s"); $canvas->page_text(500, 20, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, array(0, 0, 0)); $canvas->page_text(30, 20, "Crystal Reporting System", $font, 8, array(0, 0, 0)); $canvas->page_text(300, 20, $date, $font, 8, array(0, 0, 0)); $canvas->close_object(); $canvas->add_object($header, "all"); //For Footer $footer = $canvas->open_object(); $font = Font_Metrics::get_font("helvetica", "bold"); $canvas->page_text(30,750, "$rep_by $position", $font, 8, array(0, 0, 0)); $canvas->page_text(440,750, "crystalreportingsystem", $font, 8, array(0, 0, 0)); $canvas->close_object(); $canvas->add_object($footer, "all"); $output = $dompdf->output(); file_put_contents('pdf/'. (str_replace(' ', '-',($rep_by) .'-'. str_replace(':','.',$rep_date))). '.pdf', $output); } else { ?> <h1>View Latest Reports</h1> <p> You can now view all reports by clicking on the links on the side menu. </p> <?php } ?>

问题区域.

$_GET['rep_id']>0; if ($_GET['rep_id']!=0){ require ('includes/db.php'); mysqli_select_db($con, $db_name); $sql= 'SELECT * FROM Reports'; $stmt = $con->prepare($sql); $stmt->execute(); $stmt->bind_result($rep_id, $rep_date, $rep_ledit_date, $rep_by, $rep_type, $department, $position, $report, $rep_to); $stmt->fetch();

有错误的行.是

$stmt->execute();

谢谢!

推荐答案

我希望可以通过一些错误检查来弄清问题所在.在mysqli_select_db和$con->prepare函数之后添加or die(mysqli_error($con)):

I expect some error checking ought to shed light on the problem. Add or die(mysqli_error($con)) after the mysqli_select_db and $con->prepare functions:

require ('includes/db.php'); mysqli_select_db($con, $db_name) or die(mysqli_error($con)); $sql= 'SELECT * FROM Reports'; $stmt = $con->prepare($sql) or die(mysqli_error($con)); $stmt->execute();

关于不匹配的变量,显然表列的顺序与变量分配的顺序不对应.我猜你的表名,但我希望这能给你这个主意.更改或$sql分配为:

Regarding the mismatched variables, apparently the order of table columns is not corresponding with the order of the variable assignments. I'm guessing at your table names but I expect this gives you the idea. Change or $sql assignment to:

$sql= 'SELECT rep_id, rep_date, rep_ledit_date, rep_by, rep_type, department, position, report, rep_to FROM Reports';

或者,您可以对变量赋值进行重新排序以匹配数据库表Reports中列的顺序,但是,如果将来有人在其中添加或重新排序表列,我在上面显示的方法也不会中断.

Alternatively you could reorder the variable assignments to match the order of the columns in the database table Reports, however the way I showed you above will not break if someone where to add or reorder table columns in the future.

顺便说一句,此行顶部的目的是什么

On a side note, what is the purpose of this line at the top:

$_GET['rep_id']>0;

我没有看到作业或条件评估.看起来什么也没做.

I don't see an assignment, or conditional evaluation. Looks like it's doing nothing.

更多推荐

准备好的语句执行致命错误,变量与数据库表未命中匹配

本文发布于:2023-11-10 14:24:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575616.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   语句   错误   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!