2011-07-07 110 views
0
INSERT INTO [dbp_mod].[dbo].[Logs] (UserID, DB_Type, DB_Name, TableName, FieldName, OldValue, NewValue, SearchFields, SearchValues, Action, ActionIP, ActionTime) VALUES (1, 'DBF', 'E:\dbf\dbtest.dbf', 'E:\dbf\dbtest.dbf', 'f3', '8', '10', 'f1', '1', 'Edited', '192.168.2.124', GetDate()); 

此查詢有什麼問題?它在Management Studio中運行正常,但產生與PHP此查詢有什麼問題?

Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in錯誤

$query = "INSERT INTO [dbo].[Logs] (UserID, DB_Type, DB_Name, TableName, FieldName, OldValue, NewValue, SearchFields, SearchValues, Action, ActionIP, ActionTime) 
     VALUES ($data[UserID], '$data[DB_Type]', '$data[DB_Name]', '$data[TableName]', '$data[FieldName]', '$data[OldValue]', '$data[NewValue]', '$data[SearchFields]', '$data[SearchValues]', '$data[Action]', '$data[ActionIP]', GetDate()); "; 

    echo "<br>$query"; 
    if(!mssql_query($query, $db)){ 
     $successFlag = FALSE; 
    } else { 
     $successFlag = TRUE; 
    } 

我敢肯定,我在這兩個選擇分貝$db

INSERT INTO [dbp_mod].[dbo].[Logs] (UserID, DB_Type, DB_Name, TableName, FieldName, OldValue, NewValue, SearchFields, SearchValues, Action, ActionIP, ActionTime) VALUES (1, '', '', '', '', '', '', '', '', 'Logged in ', '192.168.2.124', GetDate()); 

沒有工作PHP和管理工作室

+0

警告:您的代碼易受sql注入攻擊。 –

+1

與db的連接存在問題。這將是'$ db'變量。 – thetaiko

回答

0

錯誤與您的數據庫連接有關,而不是您的SQL。檢查數據庫句柄,看看問題是什麼。

什麼方法可用來驗證數據庫句柄是「好」?