2014-09-20 61 views
1

,我的查詢做工精細的前四個元素,但之後它給我這個問題 和我的代碼是爲什麼查詢失敗插入我在數據庫中插入數據的數據

//Specialdeals 
-(void) insertDealsTipIntoSqlite:(NSString *)title andDetail:(NSString *)detail andStartdate:(NSString*)startDate andEnddate:(NSString*)endDate andImage:(NSString *)image andThumb:(NSString*)thumb andBranch:(NSString *)branch 
{ 
    NSString *query = [NSString stringWithFormat:@"insert into SpecialDeals(title,detail,startDate,endDate,branch,pic,thumb) values('%@','%@','%@','%@','%@','%@','%@')", title,detail,startDate,endDate, branch ,image,thumb]; 
    [self InsUpdateDelData:query]; 

} 

和我的失敗日誌

Success Query: insert into SpecialDeals(title,detail,startDate,endDate,branch,pic,thumb) values('The Lounge Manic Mondays','Mighty Mondays Offer: Get 50% discount on foot massage on 29th Sept, 2014. Start booking your appointments from Thursday 25th Sept, 2014.','2014-09-29','2014-09-29','DHA & Gulberg lahore, Islamabad and Peshawar','20442014074407.jpg','20442014074407.jpg') 

2014-09-20 19:44:13.432 Depilex[3761:60b] path is... /var/mobile/Applications/7090E701-CC89-40E7-B791-BBF89ACEA0F6/Documents/20442014074413.jpg 
2014-09-20 19:44:13.453 Depilex[3761:60b] path is... /var/mobile/Applications/7090E701-CC89-40E7-B791-BBF89ACEA0F6/Documents/20442014074413.jpg 


Success Query: insert into SpecialDeals(title,detail,startDate,endDate,branch,pic,thumb) values('The Lounge Manic Mondays','Mighty Mondays Offer: Get 50% off on shave on 22nd Sept, 2014. Start booking your appointments from Thursday 18th Sept, 2014.','2014-09-22','2014-09-22','DHA & Gulberg lahore , Islamabad & Peshawar','20442014074413.jpg','20442014074413.jpg') 

2014-09-20 19:44:25.107 Depilex[3761:60b] path is... /var/mobile/Applications/7090E701-CC89-40E7-B791-BBF89ACEA0F6/Documents/20442014074424.jpg 
2014-09-20 19:44:25.129 Depilex[3761:60b] path is... /var/mobile/Applications/7090E701-CC89-40E7-B791-BBF89ACEA0F6/Documents/20442014074425.jpg 


Failure Query: insert into SpecialDeals(title,detail,startDate,endDate,branch,pic,thumb) values('The Lounge Student Ambassador Deal','The Lounge is looking for Student Ambassador in today's fast paced , modern, fashionable and trendy world !','2014-08-24','2014-09-29','DHA & Gulberg','20442014074424.jpg','20442014074425.jpg') 

2014-09-20 19:44:25.131 Depilex[3761:60b] SQL ERROR: near "s": syntax error. In Statement: insert into SpecialDeals(title,detail,startDate,endDate,branch,pic,thumb) values('The Lounge Student Ambassador Deal','The Lounge is looking for Student Ambassador in today's fast paced , modern, fashionable and trendy world !','2014-08-24','2014-09-29','DHA & Gulberg','20442014074424.jpg','20442014074425.jpg') 
2014-09-20 19:44:56.123 Depilex[3761:60b] path is... /var/mobile/Applications/7090E701-CC89-40E7-B791-BBF89ACEA0F6/Documents/20442014074451.jpg 


    2014-09-20 19:44:56.146 Depilex[3761:60b] path is... /var/mobile/Applications/7090E701-CC89-40E7-B791-BBF89ACEA0F6/Documents/20442014074456.jpg 
Failure Query: insert into SpecialDeals(title,detail,startDate,endDate,branch,pic,thumb) values('Sante Student Brand Ambassodor','Sante The Salon is looking for a smart motivated, Fabulous ,social butterfly to represent us in today's modern & fashionable world.','2014-09-15','2014-10-31','Gulberg lahore','20452014074527.jpg','20452014074528.jpg') 
2014-09-20 19:45:28.198 Depilex[3761:60b] SQL ERROR: near "s": syntax error. In Statement: insert into SpecialDeals(title,detail,startDate,endDate,branch,pic,thumb) values('Sante Student Brand Ambassodor','Sante The Salon is looking for a smart motivated, Fabulous ,social butterfly to represent us in today's modern & fashionable world.','2014-09-15','2014-10-31','Gulberg lahore','20452014074527.jpg','20452014074528.jpg') 
+1

你的琴絃在他們撇號,這是關閉您的字符串中的查詢。 [你不應該在查詢中插入數據作爲字符串,因爲這是容易受到SQL注入](http://bobby-tables.com/) – 2014-09-20 14:53:28

回答

0

你的字符串中有一個撇號...

Failure Query: insert into SpecialDeals(title,detail,startDate,endDate,branch,pic,thumb) values('The Lounge Student Ambassador Deal','The Lounge is looking for Student Ambassador in today's fast paced , modern, fashionable and trendy world !','2014-08-24','2014-09-29','DHA & Gulberg','20442014074424.jpg','20442014074425.jpg') 

您可以在詳細信息f看看ield,你說

今天的

....

爲了解決這個問題,只需雙擊你的撇號進行轉義。例如。

今天是

+0

我upvoted,並可以接受5分鐘後:) – NullData 2014-09-20 14:58:23

+0

我dnt knw是誰做的 – NullData 2014-09-22 16:24:07