duan0414 2014-09-16 14:53
浏览 104
已采纳

“致命错误:调用未定义的函数”错误

The following error :

  Fatal error: Call to undefined function add() in E:\xampp\htdocs\paperblog\Admin\AddNewPost.php on line 18

line 18 :

 $msg=add($title,$subtitle,$details,$_FILES['_postImage']);

The whole codes (HTML ,PHP)are in the following lines.

I've 4 files:

  1. The AddNewPost.php file is the main file has the HTML code.

    • Has PHP code :
     <?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");
    ?>
    
    • And HTML:
       <form action="AddNewPost.php" method="post" id="cmntfrm" enctype= "multipart/form-data">
    
             <P align="center" style="color:#F00"><?=$msg?></P>
             <p>&nbsp; </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">&nbsp;</textarea></td>
    
                      </tr>
                      <tr>
                            <td>Post Image :</td>
                            <td><input name="_postImage" type="file"/></td>
                      </tr>
                      <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</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>
    


  1. Thepost.php file which has functions of the post form where is in the classes folder. It Has PHP code:

       <?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. 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();


                }


?>

  1. Finaly, functions.phpfile which has uploadfile function.

            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 .

  • 写回答

2条回答 默认 最新

  • dongyi5817 2014-09-16 14:56
    关注

    add() is not a function. It is a method of a class called "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']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题