PHP UserID到数据库

时间:2012-05-15 20:47:31

标签: php sql database

首先,我将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为字符串,对象在/

中给出

1 个答案:

答案 0 :(得分: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']) . "'
        );";