2012-05-15 55 views
0

首先我得到的BedrijfID了會議PHP用戶ID數據庫

$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) . "' 
            );"; 

錯誤:

Warning: mysqli::real_escape_string() expects parameter 1 to be string, object given in /

+2

將您的SQL回顯至屏幕以查看實際正在生成的內容,然後您將能夠看到哪個調用正在生成錯誤。 – andrewsi

+1

我覺得情操部分是缺失的,我們得到了你的$ res,但不是對象的影響。 – Sebas

+5

'$ res'可能是一個對象,您正試圖將它傳遞給'$ conn-> real_escape_string($ res)' – cspray

回答

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']) . "' 
     );"; 
+0

謝謝,它的工作原理 – user1385694

+0

不客氣。請記住接受答案(左上方的複選標記)。 – webbiedave

相關問題