致命错误:在字符串上调用成员函数

肯齐耶·弗拉维乌斯(Kenziiee Flavius)

连接在这里

class connection{

private $hostname = "localhost";
private $username = "root";
private $password = "";
private $database = "idea";
private $conn;

public function __construct(){
    $this->conn = new mysqli($this->hostname, $this->username, $this->password, $this->database)or die("Error Connection To MySQL");
}

public function getConn(){
    return $this->conn;
}
?>

我怀疑它的联系,但只是万一...它一直在为所有其他查询工作,但谁知道。

其次,这里的所有内容都是这样

    <?php 
session_start();

  if ($_SESSION['loggedin'] != 1) {
    header('location: index.php');
  }

    include 'connection.php';
    include 'users.php';
    include 'ideas.php';
    $conn = new connection();
    $user = new users($conn->getConn());
    $idea = new ideas($conn->getConn());
    ?>

倒数第二个是我在一个类中的查询

<?php 

class ideas{

    private $conn;

    public function __construct($db){
        $this->conn = $db;
    }

    public function checkIdea($title){
        $result = $this->conn->query("SELECT * FROM ideas WHERE title = '$title'");
        return $result;
    }
?>

现在最后是我在主页上调用的功能!

<?php 
            if (isset($_POST['addidea'])) {
              $title = mysql_real_escape_string($_POST['title']);
              $idea = mysql_real_escape_string($_POST['idea']);

              $check = $idea->checkIdea($title); // <-- sais this is the error here...

              if ($check->num_rows == 0) {
                echo $idea->getUserId($_SESSION['username']);
              }else{
                echo "Sorry that iDea title is already taken, please use another!";
              }
            }
          ?>

我不知道为什么要这样做,这是什么错误,我以前从未遇到过(调用字符串上的成员函数)我使用了与我登录时相同的查询/布局,也不知道为什么要这样做赞赏。

加布里埃尔·豪克洛克(Gabriel Hautclocq)

你在做 :

$idea = mysql_real_escape_string($_POST['idea']);

所以$ idea现在是一个字符串。然后,您可以:

$check = $idea->checkIdea($title);

字符串上没有checkIdea方法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

致命错误:在字符串上调用成员函数prepare()

致命错误:在字符串上调用成员函数Createuser

致命错误:未捕获的错误:在字符串上调用成员函数 fetch()

致命错误:未被捕获的错误:在字符串上调用成员函数fetch_object()

致命错误:在字符串上调用成员函数fetch_assoc()

Magento 2致命错误:在字符串上调用成员函数getAttributeText()

PHP 致命错误:在字符串上调用成员函数 format()

致命错误:构建PHP过滤系统时,在字符串上调用成员函数result()

错误:在字符串上调用成员函数setPayrollperiodid()

Laravel错误:在字符串上调用成员函数format()

错误:在字符串上调用成员函数 addDays()

错误:在字符串上调用成员函数storeAs()

Laravel 错误:在字符串上调用成员函数 format()

在laravel中的字符串上调用成员函数format()

在字符串上调用成员函数all()(查看:

PHP:在字符串上调用成员函数contains()

Yii 2 在字符串上调用成员函数 saveAs()

在字符串上调用成员函数addEagerConstraints()

在字符串上调用成员函数fill()

在字符串上调用成员函数 setDate()

在 Yii 的字符串上调用成员函数 saveAs()

在laravel中的字符串上调用成员函数latest()

在字符串上调用成员函数guessExtension()

Laravel 5.6:在字符串上调用成员函数getRealPath()

在字符串上调用成员函数getRealPath()

在 Laravel 的字符串上调用成员函数 has()

在字符串上调用成员函数canBeViewed()

Laravel - 在字符串上调用成员函数 save()

在字符串上调用成员函数notify()