467,915 Members | 1,356 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

MSSQL Error stumping me

Mr aldo
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:
Expand|Select|Wrap|Line Numbers
  1. 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.
Dec 24 '08 #1
  • viewed: 3188
Share:
3 Replies
ck9663
Expert 2GB
Too much quote on this one:

SUBSTRING('Database Error: Incorrect syntax near ''127''.', 1, 65534)
Dec 24 '08 #2
Mr aldo
Ah, ok. Then I have a question on how you sanitize MSSQL data? I know in PHP for MySQL it has mysql_real_escape_string but I see nothing for MSSQL
Dec 24 '08 #3
ck9663
Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. declare @smf_log_errors  table 
  2. (
  3. [id_member] int,
  4. [log_time] bigint,
  5. [ip] varchar(20),
  6. [url] varchar(max), 
  7. [message] varchar(max), 
  8. [session] varchar(50), 
  9. [error_type] varchar(50), 
  10. [file] varchar(300), 
  11. [line] int
  12. )
  13.  
  14. INSERT INTO @smf_log_errors ([id_member], [log_time], [ip], [url], [message], [session], [error_type], [file], [line]) 
  15. 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)
  16.  
  17.  
  18. select * from @smf_log_errors 
  19.  
-- CK
Dec 24 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by mj | last post: by
2 posts views Thread by SteveS | last post: by
1 post views Thread by theintrepidfox | last post: by
14 posts views Thread by guswebb | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.