By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,419 Members | 1,636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,419 IT Pros & Developers. It's quick & easy.

MSSQL Error stumping me

Mr aldo
P: 15
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
Share this Question
Share on Google+
3 Replies


ck9663
Expert 2.5K+
P: 2,878
Too much quote on this one:

SUBSTRING('Database Error: Incorrect syntax near ''127''.', 1, 65534)
Dec 24 '08 #2

Mr aldo
P: 15
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 2.5K+
P: 2,878
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.