【发布时间】:2015-07-27 03:47:45
【问题描述】:
连接在这里
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!";
}
}
?>
我不知道它为什么这样做,这个错误是什么我以前从未遇到过(调用字符串上的成员函数)我使用与登录时相同的查询/布局等不知道它为什么这样做对此任何答案表示赞赏。
【问题讨论】: