0

首先,我从会话中获取 BedrijfID

$Deals = $_SESSION['login'];
$sSql = "SELECT BedrijfID FROM tblBedrijf WHERE Email  = '$Deals'";     
$res = $conn->query($sSql); 
return $res;

比我需要把它放在另一个表中

$sql = "INSERT INTO tblDeal (Dealnaam, Dealkeuze, Dealbeschrijving,BedrijfID) 
                                    VALUES 
                                    (
                                    '" . $conn -> real_escape_string($this -> m_sNaamdeal) . "', 
                                    '" . $conn -> real_escape_string($this -> m_sAantal) . "',
                                    '" . $conn -> real_escape_string($this -> m_sBeschrijving) . "',
                                    '" . $conn -> real_escape_string($res) . "'
                                    );";

错误:

警告:mysqli::real_escape_string() 期望参数 1 是字符串,对象在 /

4

1 回答 1

2

您需要先获取一行:

$Deals = $_SESSION['login'];
$sSql = "SELECT BedrijfID FROM tblBedrijf WHERE Email  = '$Deals'";     
$res = $conn->query($sSql);

$row = $res->fetch_assoc();

$sql = "INSERT INTO tblDeal (Dealnaam, Dealkeuze, Dealbeschrijving,BedrijfID) 
        VALUES 
        (
        '" . $conn -> real_escape_string($this -> m_sNaamdeal) . "', 
        '" . $conn -> real_escape_string($this -> m_sAantal) . "',
        '" . $conn -> real_escape_string($this -> m_sBeschrijving) . "',
        '" . $conn -> real_escape_string($row['BedrijfID']) . "'
        );";
于 2012-05-15T20:53:10.783 回答