0
아래 코드에 대한 질문이 있습니다. 하나의 항목 (이 경우 거리)을 선택하려면 모든 것이 디버깅 모드에서 오류없이 작동합니다. 내가 오류 (공지 가지고 내 선택 쿼리에 추가 매개 변수를 추가 할 때MAMP에서 객체가 아닌 속성을 얻으려고 시도합니다.
public function placeAvailable()
{
//open connectie naar database
include("Connection.php");
$sSql= "select Street from tblPlaces
where Street = '".$this->m_sStreet."'";
$vResult=$mysqli->query($sSql);
if($vResult->num_rows>0)
{
return(false);
}
else
{
return(true);
}
$mysqli->close();
}
(나는 메시지를 생성하기 위해 AJAX를 사용하고 있습니다) : 비 - 개체의 속성을 얻으려고 노력/응용 프로그램/라인 (86)에 MAMP/htdocs에/foodsquare/자산/클래스/places.class.php)
$vResult=$mysqli->query($sSql);
if($vResult->num_rows>0)
내가 추가 한 추가 매개 변수는 folowing입니다.
$sSql= "select Street from tblPlaces
where Street = '".$this->m_sStreet."' AND where HouseNumber = '".$this->m_sHouseNumber."'";
조쉬 여기 당신이 $mysqli
정의 결코 전체 코드
<?php
class Places {
private $m_sName;
private $m_sStreet;
private $m_sHouseNumber;
private $m_sCity;
private $m_sCategory;
public function __set($p_sProperty, $p_vValue) {
switch($p_sProperty) {
case "Name" :
$this -> m_sName = $p_vValue;
break;
case "Street" :
$this -> m_sStreet = $p_vValue;
break;
case "HouseNumber" :
$this -> m_sHouseNumber= $p_vValue;
break;
case "City" :
$this -> m_sCity = $p_vValue;
break;
case "Category" :
$this -> m_sCategory = $p_vValue;
break;
}
}
public function __get($p_sProperty) {
$vResult = null;
switch($p_sProperty) {
case "Name" :
$vResult = $this -> m_sName;
break;
case "Street" :
$vResult = $this -> m_sStreet;
break;
case "HouseNumber" :
$vResult = $this -> m_sHouseNumber;
break;
case "City" :
$vResult = $this -> m_sCity;
break;
case "Category" :
$vResult = $this -> m_sCategory;
break;
}
return $vResult;
}
public function addPlaces()
{
include_once("connection.php");
$sSql = "INSERT INTO tblPlaces
(Name,
Street,
HouseNumber,
City,
Category)
VALUES
('" . $mysqli -> real_escape_string($this -> m_sName) . "',
'" . $mysqli -> real_escape_string($this -> m_sStreet) . "',
'" . $mysqli -> real_escape_string($this -> m_sHouseNumber) . "',
'" . $mysqli -> real_escape_string($this -> m_sCity) . "',
'" . $mysqli -> real_escape_string($this -> m_sCategory) . "');";
if (!$mysqli -> query($sSql))
{
throw new Exception("Er is iets mis gelopen bij het toevoegen van een plaats");
}
}
public function placeAvailable()
{
//open connectie naar database
include("Connection.php");
global $mysqli;
//sql query selecteert straat uit tblplaces waar de straat gelijk is aan het inputveld street uit het formulier
$sSql= "select Street from tblPlaces
where Street = '".$this->m_sStreet."' AND where HouseNumber = '".$this->m_sHouseNumber."'";
$vResult=$mysqli->query($sSql);
if($vResult->num_rows>0)
{
//Street (place) is al in gebruik
return(false);
}
else
{
//Hij is nog niet in gebruik
return(true);
}
//database sluiten
$mysqli->close();
}
}
?>
조쉬 감사합니다. 나는 이것을 시도 할 것입니다. 하지만 왜 그것이 1 매개 변수와 함께 2와 함께 작동 궁금 해서요. 내 DB 연결 ($ mysqli) connection.php 파일에 편집 : 조쉬, 여전히 글로벌 $ mysqli와 함께이 오류가 발생; – Niels
@Niels : 당신은'm_sHouseNumber'에 오류가있을 가능성이 큽니다. 테스트를 위해서'echo $ this-> m_sHouseNumber;'를 추가하고 에러가 발생했는지 확인하십시오. 그렇다면 클래스에 명시된 명시 적 속성이 없거나 암시 적 속성에 아무 것도 지정하지 않은 것입니다 (나중에 읽을 때 실패 함). – Josh
내 수업에서이 속성의 이름을지었습니다. 원래 게시물에서 편집을 봅니다. (전체 게시물을이 게시물에 넣었습니다) – Niels