需要/包含在php中
我需要一些帮助,我有2个php文件,当我调用一些函数时,它告诉我 致命错误:在第13行的/home/f77inq/public_html/php/shares.php中调用未定义的函数get_contents() 即使在我调用我键入的函数的文件中需要(“我的文件名”) shares.php需要/包含在php中,php,file,require,classnotfound,Php,File,Require,Classnotfound,我需要一些帮助,我有2个php文件,当我调用一些函数时,它告诉我 致命错误:在第13行的/home/f77inq/public_html/php/shares.php中调用未定义的函数get_contents() 即使在我调用我键入的函数的文件中需要(“我的文件名”) shares.php <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-stri
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Shares</title>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
adad
<?php
$data = get_contents();
print_contents($data);
?>
</body>
</html>
分享
阿达德
这是我调用函数的文件
<?php
require("../../php_include/services.php");
require("../../php_include/query.php");
putenv("ORACLE_HOME=/oracle/product/12.1.0/dbhome_1");
function get_contents() {
$conn = db_connect();
$shares = get_share($conn);
db_disconnect($conn);
$contents = array('shares' => $shares);
return $contents;
}
function print_contents($contents) {
?>
<table>
<tr>
<th>Company Name</th>
<th>Rate</th>
</tr>
<?php
foreach ($contents['shares'] as $share) {
print "<tr>";
//****** LINKS TO EVERY
$identifier = urlencode($share['COMPANY']);
print "<td><a href='share-details.php?company={$identifier}'>{$share['COMPANY']}</a></td>";
print "<td>{$share['RATE']}</td>";
print "</tr>";
}
?>
</table>
<?php
}
require ("shares.php"); //<<<<<<<<<<<<<<<<<<<<<<
?>
公司名称
比率
为了进行测试,我将这段代码放在一个名为like.php的文件中-
<?php
function get_contents() {
echo "Got it";
}
require ("shares.php");
?>
在shares.php文件中,我使用了这个-
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Shares</title>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
<?php
$data = get_contents();
echo $data;
?>
</body>
</html>
分享
它可以完美地工作,没有任何错误。您显示的错误来自文件shares.php
,但是需要的文件是shares.php
。此错误可能发生在过程中的其他地方,因为您显示的所有代码都是有效的,并且肯定可以正常工作。您是否将php文件包含在share.php文件中?这似乎有点倒退。通常,您会将函数放在脚本中,然后用require
加载到调用函数的脚本中。@habibulhaq他是这样做的:定义函数的脚本包括share.php
。转到第二个脚本的末尾。@KhairulIslam这没有意义。@Nico12345,这里的代码是绝对有效的,工作正常。还有一些你不知道的事情发生了,在文件的顶部运行debug\u print\u backtrace()
,看看它被加载到哪里。对我来说,这仍然是一个奇怪的错误((@Nico12345,你需要找出如何给我们真正的出错代码。这个代码不是无效的。@KorvinSzanto我和Khairl做了同样的事情,我也遇到了同样的问题。他不知道他在说什么。他的建议毫无意义。等等,等等@Nico12345让我们在浏览器中知道你正在运行的url。这是类似的localhost/like.php
或localhost/shares.php
?它实际上是共享的,我再次输入了)。看起来好像是数据库有问题,或者我不知道,因为我做得对(@Nico12345您粘贴的错误显示为“shares.php”,这不能由数据库问题或类似问题引起。您提供的信息不正确。