我基本上是尝试将GET值从构造函数传递给insert_update函数。我已经删除了很多后一种功能。此外,如果值得注意,此页面是一个包含页面。
class Updates {
function __construct(){
$owner = $this->get = array_map('mysql_real_escape_string', $_GET);
$owner=$owner["member_id"];
echo $owner;
}
//Insert Update
public function Insert_Update()
{
$query = mysql_query("INSERT INTO `field` (foo) VALUES (N'$owner')") or die(mysql_error());
}
答案 0 :(得分:0)
您可以owner
成为Updates
的成员,并将其存储在this->owner
。
答案 1 :(得分:0)
class Updates {
private $owner;
function __construct(){
$owner = $this->get = array_map('mysql_real_escape_string', $_GET);
$this->owner=$owner["member_id"];
echo $this->owner;
}
//Insert Update
public function Insert_Update()
{
$query = mysql_query("INSERT INTO `field` (foo) VALUES (N'".$this->owner."')") or die(mysql_error());
}
}
答案 2 :(得分:0)
class Updates {
protected $owner;
function __construct($myGetVariable)
$this->owner = $myGetVariable;
}
//Insert Update
public function Insert_Update()
{
// you can access the variable by typing:
echo $this->owner;
$query = mysql_query("INSERT INTO `field` (foo) VALUES (N'".$this->owner."')") or die(mysql_error());
}
*抱歉不得不编辑几次,复制和粘贴不正确,然后我想让它更清晰。