我想發送數據到我的數據庫(group_id,user_id和group_name),但只有前兩個進入數據庫。當我var_dump $groupinvitation->Invitation_group_name = mysql_real_escape_string($groupname);
它給了我正確的group_name。我究竟做錯了什麼?(不是全部)數據不能到達數據庫
當我與它的工作以及一個隨機單詞替換'" . $db->conn->real_escape_string($this->Invitation_group_name) . "'
..
PHP
$groupinvitation = new GroupInvitation();
if (isset($_POST["Accept"])) {
try {
$group_id = mysql_real_escape_string($_POST["group_id"]);
$groupinfo = $group->GetGroupInfoByGroupId($group_id);
$groupname = $groupinfo['group_name'];
$requestnumber = mysql_real_escape_string($_POST['acceptID']);
$groupinvitation->AddAsGroupMember($number, $group_id);
$groupinvitation-> AcceptGroupRequest($requestnumber);
$groupinvitation->Invitation_group_name = mysql_real_escape_string($groupname);
$feedback = "Awesome, You just added a friend!";
} catch(Exception $e) {
$feedback = $e -> getMessage();
}
}
的聲明:
class GroupInvitation
{
private $m_sGroup_invitation_group_name;
public function __set($p_sProperty, $p_vValue)
{
switch($p_sProperty)
{
case "Invitation_group_name":
$this->m_sGroup_invitation_group_name = $p_vValue;
break;
}
}
public function __get($p_sProperty)
{
switch($p_sProperty)
{
case "Invitation_group_name":
return $this->m_sGroup_invitation_group_name ;
break;
}
}
功能:
public function AddAsGroupMember($number, $group_id)
{
$db = new Db();
$insert = "INSERT INTO tblgroup_member(
group_id,
user_id,
group_name
) VALUES (
'" . $db->conn->real_escape_string($group_id) . "',
'" . $db->conn->real_escape_string($number) . "',
'" . $db->conn->real_escape_string($this->Invitation_group_name) . "'
)";
$db->conn->query($insert);
}
首先,我建議你使用PDO。它更安全,易於使用。你可以在這裏找到完整的文檔:http://www.php.net/manual/en/book.pdo.php。我現在正在尋找解決您的問題的方法;) – Lapinou
當您在函數中var_dump時,$ this-> Invitation_group_name'會返回什麼結果? – Daan
它正在返回group_name – Lisa