连接在这里
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!";
}
}
?>
我不知道为什么要这样做,这是什么错误,我以前从未遇到过(调用字符串上的成员函数)我使用了与我登录时相同的查询/布局,也不知道为什么要这样做赞赏。
你在做 :
$idea = mysql_real_escape_string($_POST['idea']);
所以$ idea现在是一个字符串。然后,您可以:
$check = $idea->checkIdea($title);
字符串上没有checkIdea方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句