开发者

Unidentified Property; Trying to get property of non-object

Unidentified Property; Trying to get property of non-object

Hi. I've been trying to create a PHP page using Savant Templating Engine that performs some CRUD operations via XAMPP. As I coded the page and tried to run the page, I found the above errors that showed up. But as I inserted the values into the textbox and textarea respectively and hit the publish button, I found that the database is being updated successfully. What is the probable reason for the above issue? And How do I get out of the problem.

I t开发者_开发问答ried to search for existing threads regarding the same, but none of them seemed to address my problem. Please do help out citing the link below if any of the existing threads addresses my issue. Thanks. :)

-------------------------------------------------------------update--------------------------------------------------------------

view.html

<html>
    <head>
        <title>Create Post: Blog: Design & Social Media</title>
    </head>
    <body>
        <form action="../../applications/create/index.php" method="POST">
            <input type="text" name="title" value="<?php echo $this->b->title; ?>"/>
            <input type="submit" value="Publish" />
            <br/>
            <textarea rows="2" cols="20" name="content"><?php echo $this->b->content; ?></textarea>
        </form>
    </body>
</html>

index.php

<?php
    include_once ('../../classes/models/blog.php');
    include_once ('../../resources/libraries/savant3.php');
    $s=new savant3();
    $s->method=$_SERVER['REQUEST_METHOD'];
    $b=new blog();
    if($_SERVER['REQUEST_METHOD']=="GET")
    {
    }
    else
    {
        $b->title=$_POST['title'];
        $b->content=$_POST['content'];
        Blog::create($b);
        header('location:../../applications/success/index.php');
        return;
    }
    $s->display('view.html');
?>

Blog.php

<?php
    class Blog
    {
        public $id;
        public $title;
        public $content;
        public $created;

        public static function create(Blog $b)
        {
            $title=$b->title;
            $content=$b->content;
            $m=new mysqli("localhost","root","","kartik_iyer");
            $s=$m->prepare("insert into blog values(null,?,?,null)");
            $s->bind_param('ss', $title, $content);
            $s->execute();
        }

        public static function readSingle($id)
        {
        }

        public static function readAll()
        {
        }

        public static function update(Blog $b)
        {
        }

        public static function delete($id)
        {
        }
    }
?>


You are getting this messages because your error reporting is set to -1 = error_reporting(-1); or at least the notices are enabled. This means, that all possible error messages get displayed, especially the notices, that usually are not enabled. I just recently asked about error reporting in this topic.
Conclusion was, that you should write your code to fit the highest standards, but you shouldn't fix somebody existing code.

I would recommend to find the line, that is setting error reporting to -1 remove it. Or override it with: error_reporting(E_ERROR | E_WARNING | E_PARSE);. This will set it as default.

Or you can optimize your code with empty(), isset() and or presetting some variables to NULL.

Anyways, read my link on Programmers and you will understand the need-to-know-basis about error reporting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜