[英]“Fatal error: Call to undefined function ” Error
The following error : 出现以下错误:
Fatal error: Call to undefined function add() in E:\xampp\htdocs\paperblog\Admin\AddNewPost.php on line 18
line 18 : 第18行:
$msg=add($title,$subtitle,$details,$_FILES['_postImage']);
The whole codes ( HTML
, PHP
)are in the following lines. 整个代码(
HTML
, PHP
)在以下几行中。
I've 4 files: 我有4个文件:
The AddNewPost.php
file is the main file has the HTML
code. AddNewPost.php
文件是具有HTML
代码的主文件。
PHP
code : PHP
代码: <?php include_once("..\\DB.php"); include_once("..\\Classes\\post.php"); $title=""; $subtitle=""; $details=""; $msg=""; if(isset($_POST['_PostSubmit'])) { $title=$_POST['_PostTitle']; $subtitle=$_POST['_PostSubTtile']; $details=$_POST['_PostDetails']; if( !empty($title)||!empty($subtitle)||!empty($details) ) { $msg=add($title,$subtitle,$details,$_FILES['_postImage']); } else $msg=" The post is empty "; } include_once("Header.php"); ?>
HTML
: HTML
: <form action="AddNewPost.php" method="post" id="cmntfrm" enctype= "multipart/form-data"> <P align="center" style="color:#F00"><?=$msg?></P> <p> </p> <table width="600" border="0" align="center"> <img src="../images/addNewPost.png"/> <br /> <br /> <tr> <td width="131">Post Title <h8 style="color:#F00">*</h8>:</td> <td width="443"><input name="_PostTitle" type="text" /></td> </tr> <tr> <td>Post Sub Title <h8 style="color:#F00">*</h8>:</td> <td><input name="_PostSubTtile" type="text" /></td> </tr> <tr> <td>Post Details :</td> <td><textarea name="_PostDetails" cols="32" rows="7"> </textarea></td> </tr> <tr> <td>Post Image :</td> <td><input name="_postImage" type="file"/></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td></td> <td><input name="_PostSubmit" type="submit" value="Save" id="submit" /></td> </tr> </table> <center> <img src="../Post_Imges/a.jpg" height="420" width="460" /> </center>
The post.php
file which has functions of the post form where is in the classes folder. post.php
文件,具有post表单的功能,位于classes文件夹中。 It Has PHP
code: 它具有
PHP
代码:
<?php include_once("../DB.php"); class post{ var $Post_ID; var $title,$subtitle,$postdetail,$Post_Imgs; var $pmonth ,$pyear ,$pday; function add($title,$subtitle,$postdetail,$file){ $query=" insert into post(Title,SubTitle,PostDetails,PDay,PMonth,PYear) values('$title,'$subtitle','$postdetail'".date("d").",".date("m").",".date("Y").")"; $this->Post_ID=$this->GetLastPostId(); $msg=test("Add",$query); $msg.="<br/>".$this->uploadImage($file); return $msg; } function GetLastPostId(){ $query="select Max(Post_ID) from Post"; $result=mysql_query($query); $row=mysql_fetch_row($result); return $row[0]; } function uploadImage($file){ uploadFile("Post_Imges\\$Post_ID.jpg",$file); } } ?>
3.The DB.php
file which has some function for DB. DB.php
文件,对DB具有某些功能。 It has : 它具有:
<?php
include_once("functions.php");
mysql_connect("localhost","root","");
mysql_select_db("paperbloge");
function test($test ,$query){
mysql_query($query);
if(!empty(mysql_errno()))
return "Post ".$test." Successfully" ;
else
return "Error".mysql_errno().":".mysql_error();
}
?>
Finaly, functions.php
file which has uploadfile function. 最后,具有uploadfile功能的
functions.php
文件。
function uploadFile($folderPathFileName,$file){ if (!empty($file['tmp_name'])){ move_uploaded_file($file['tmp_name'],$_SERVER['DOCUMENT_ROOT']."\\paperblog\\ ".$folderFileName); $msg.="<br/> Image uploaded Successfully"; } else $msg= "Image File too large or No Image File"; return $msg; } ?>
Thats the whole codes that i've . 那就是我的全部代码。
Does anyone know what is wrong here that cause this problem? 有谁知道这是什么问题导致了这个问题?
Thanks 谢谢
Ya it's working , But have some errors again . 是的,它正在工作,但是又有一些错误。 Thanks for your helping .
感谢您的帮助。
add
is part of the class post
add
是课程post
一部分
Change your line to; 将行更改为;
$objPost = new post();
$msg = $objPost->add($title,$subtitle,$details,$_FILES['_postImage']);
add()
is not a function. add()
不是函数。 It is a method of a class called "post". 它是称为“ post”的类的方法。 That means you have to instantiate that class and then call that method:
这意味着您必须实例化该类,然后调用该方法:
$post = new Post();
$msg=$post->add($title,$subtitle,$details,$_FILES['_postImage']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.