MSSQL Error stumping me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mr aldo
    New Member
    • Jul 2007
    • 15

    MSSQL Error stumping me

    I am currently getting this MSSQL Error I cannot for the life of me figure out... The error is:

    Incorrect syntax near '127'.
    This is the query:
    Code:
    INSERT INTO [dbo].smf_log_errors ([id_member], [log_time], [ip], [url], [message], [session], [error_type], [file], [line]) VALUES (0, 1230104368, SUBSTRING('127.0.0.1', 1, 16), SUBSTRING('?http://localhost/mssql/smf/', 1, 65534), SUBSTRING('Database Error: Incorrect syntax near ''127''.', 1, 65534), '70adcf6f3d36b592f5ea01046fd4e34d', 'database', SUBSTRING('C:/xampp/htdocs/mssql/smf/Sources/Security.php', 1, 255), 303)
    The thing is, if I do that query in Microsoft SQL Server Management Studio, I get no errors at all... but if I use it with PHP's mssql_query, thats where the error comes in.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Too much quote on this one:

    SUBSTRING('Data base Error: Incorrect syntax near ''127''.', 1, 65534)

    Comment

    • Mr aldo
      New Member
      • Jul 2007
      • 15

      #3
      Ah, ok. Then I have a question on how you sanitize MSSQL data? I know in PHP for MySQL it has mysql_real_esca pe_string but I see nothing for MSSQL

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Where are you running it? I think the code on your front-end is the one having problems.

        As it is, the INSERT is good.

        Try this on your SQL Analyzer:
        Code:
        declare @smf_log_errors  table 
        (
        [id_member] int,
        [log_time] bigint,
        [ip] varchar(20),
        [url] varchar(max), 
        [message] varchar(max), 
        [session] varchar(50), 
        [error_type] varchar(50), 
        [file] varchar(300), 
        [line] int
        )
        
        INSERT INTO @smf_log_errors ([id_member], [log_time], [ip], [url], [message], [session], [error_type], [file], [line]) 
        VALUES (0, 1230104368, SUBSTRING('127.0.0.1', 1, 16), SUBSTRING('?http://localhost/mssql/smf/', 1, 65534), SUBSTRING('Database Error: Incorrect syntax near ''127''.', 1, 65534), '70adcf6f3d36b592f5ea01046fd4e34d', 'database', SUBSTRING('C:/xampp/htdocs/mssql/smf/Sources/Security.php', 1, 255), 303)
        
        
        select * from @smf_log_errors
        -- CK

        Comment

        Working...